I am using will_paginate in Rails. To leverage Turbo Frames I have put the entire pagination area into a Turbo Frame. So selecting page 3 changes the tag to:
The form submits the changes properly. However I am not sure how to properly redirect back to page 3. Do I need to add the page number as a hidden field in the form and use that to find out which page the user was on? I hope there is a nicer way to actually redirect back to where the user actually came from.
At this point the page number is already lost. And the referer is:
Referer: http://localhost:3000/packages/vlc
So I assume that Turbo takes the referer as shown in the browser URL field and not the “src” of the turbo-frame.
I could add a hidden field with the proper URL to redirect back to. However now that you mention the ‘Referer’ field I wonder if Turbo should change the Referer to reflect the “src” attribute. Should I add an issue on Github? Or am I just doing something wrong?
I think this should Just Work. The referrer header comes from the request, it’s nothing to do with the browser URL, which, as you say, is different in your case. This has always worked ok for me. Maybe the issue is the ?page query param. I’d try poking at the request through dev tools and seeing what you get.
Yes, that’s correct. The larger part of the page is wrapped in a frame I call “mainframe”. That frame consists of further elements that each use dom_id() like “screenshot_19519”. As far as I understand the Hotwire/Turbo documentation that is not a problem.
I think I see what you are trying to say. The outer frame contains the page number but the inner frame does not. The paginator uses the outer frame. The form I’m using (for in-place editing) is using the inner frame.
I will try to avoid that kind of nesting and see if that helps.
You’re correct, you should not have any issues with nested Turbo-Frames. As you partially pointed out, if the outer frame contains the pagination URL and the inner frame contains a sub element and form, after save why do you need to redirect the outer frame? Would it work for your scenario to just update the contents of the sub element frame?
Just wanted to get back and thank you both for your feedback. Turbo Frames indeed does the right thing. I just didn’t use the page number properly in the URL so it didn’t know where to redirect back to. You helped me figure that out.