Ask A Question

Notifications

You’re not receiving notifications from this thread.

Anchors being ignored when added to redirect_to path in controller

RJ McCollam asked in Rails β€’

I feel I am missing something fundamental, or maybe just silly, when it comes to this issue.

I am utilizing linking to anchors in most places in an app I am building and all is working well with links in the view. Formatting my path like...

sample_path(anchor: "sample_anchor")

When I attempt this via my controller via a patch method it is not taking you to the anchor when the page is loaded. Setup in my controller for the redirect_to is like...

redirect_to some_page_path(anchor: "some_anchor"), notice: "Some notice"
Reply

I had to change my link to a button and set data-turbo to false in order for it to respond to what I needed it to.

Reply

Oh my gosh RJ! Thank you!! (I signed up to GoRails just so I could thank you!)
I honestly have been dealing with this issue for HOURS, when I finally came across your post!
I mean it should be as simple as adding an anchor tag to your redirect path, right? WRONG, if you're using turbo-streams. 🀦🏻 Didn't even think of adding data { turbo: false } to my button. 🀦🏻 Thank you, thank you! πŸ€©πŸ™ŒπŸ»

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 82,329+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.