Rails-向redirect_to添加哈希

chr*_*o16 17 ruby-on-rails ruby-on-rails-3

我需要指定一个哈希来添加到redirect_to.我该怎么做呢?

这就是我的redirect_to的形成方式:

 redirect_to :action => 'show', :id => @consultant.id
Run Code Online (Sandbox Code Playgroud)

我需要去example.com/consultant/#some_hash

谢谢!

noo*_*odl 30

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

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


hav*_*asi 8

我遇到了类似的问题.我试过这个:

redirect_to @post, anchor: 'tab_items'
Run Code Online (Sandbox Code Playgroud)

但没有使用rails 4.2.6.但是,如果我改为以下,现在工作正常:

redirect_to post_path(@post, anchor: 'tab_items')
Run Code Online (Sandbox Code Playgroud)