代码之家  ›  专栏  ›  技术社区  ›  christo16

Rails-添加哈希以重定向到

  •  16
  • christo16  · 技术社区  · 14 年前

    我需要指定要添加到重定向的哈希。我该怎么做?

    这就是我重定向到的方式:

     redirect_to :action => 'show', :id => @consultant.id
    

    我需要去example.com/consultant/#some#u hash

    谢谢!

    2 回复  |  直到 14 年前
        1
  •  30
  •   noodl    14 年前

    尝试 redirect_to your_current_options, :anchor => 'fragment_identifier'

    http://api.rubyonrails.org/classes/ActionDispatch/Routing/UrlFor.html#method-i-url_for

        2
  •  8
  •   havasi    9 年前

    我也有类似的问题。我试过这个:

    redirect_to @post, anchor: 'tab_items'
    

    但在使用rails 4.2.6时不起作用。但如果我改成了下面的,现在工作正常了:

    redirect_to post_path(@post, anchor: 'tab_items')