christo16
christo16

Reputation: 4843

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!

Upvotes: 17

Views: 8667

Answers (2)

havasi
havasi

Reputation: 567

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')

Upvotes: 10

noodl
noodl

Reputation: 17408

Try redirect_to your_current_options, :anchor => 'fragment_identifier'

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

Upvotes: 34

Related Questions