Hi, I’m using a nested route for company, document
The document has many subsections
After updating a subsection, I want to redirect_to the (company, document) AND THEN scroll down to the subsection
In the view I have id=“<%= dom_id(subsection) %>” and if I add #subsection_ to the url in my browser it jumps to exactly where it should.
After successfully updating a subsection on a separate edit page, I can redirect_to the company, document page will then displays the document.subsections.each with the correct anchor ids.
I would like the redirect_to (with the nested routes) to the anchor, but I can’t get it working.
I know the redirect_to url is being created correctly because I have added the same thing to the notice: but it doesn’t appear in the url. I suspect that it has something to do with Turbo Frames but my searches haven’t revealed anything.
I’m not looking for suggestions on how my app should work or what I’m doing wrong. The decisions that have been made are for very good reasons. Just need some anchor help please.
I’m not sure if this is a correct way of solving this, but I had a similar issue and one way to “escape” turbo and force the browser to follow redirect is to add format: :html as a parameter in routes method (whatever_path(..., format: :html)).
Might work for you as a workaround until a more proper solution comes up.
Thank you. It got me closer - the problem seems to be that putting a ‘#’ in the redirect_to
If I leave it out I can add anything to the end of the redirect. Put it in and everything in the url up to and including the ‘#’ disappears.
I’ve tried raw, html_safe
I’m thinking I can pass the id in the notice: and then use JavaScript to scroll. Or make the sections different. It was supposed to be a quick fix but has taken ages with no end in sight.
anchor: doesn’t appear to do anything or maybe it does but gets stripped out. Time to look at the source.