Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails- add hash to redirect_to

I need to specify a hash to add to a redirect_to. How do I do this?

This is how my redirect_to is formed:

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

I need to go to example.com/consultant/#some_hash

Thanks!

like image 442
christo16 Avatar asked Nov 23 '10 12:11

christo16


2 Answers

Try redirect_to your_current_options, :anchor => 'fragment_identifier'

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

like image 100
noodl Avatar answered Oct 12 '22 03:10

noodl


I had a similar problem. I tried this:

redirect_to @post, anchor: 'tab_items'

but not worked using rails 4.2.6. But if I've changed to the following, and now works fine:

redirect_to post_path(@post, anchor: 'tab_items')
like image 37
havasi Avatar answered Oct 12 '22 03:10

havasi