All threads / Anchors being ignored when added to redirect_to path in controller

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"

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.

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! 🤩🙌🏻

Join the discussion

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

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

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

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2021 GoRails, LLC. All rights reserved.