I’m working on a project that uses a strategy similar to Turbolinks and Pjax on the client, so all forms and links are sent to the server using AJAX requests.
HTTP redirects don’t work well with AJAX, so instead of a raw redirect the server responds with a “JSON encoded” redirect, and the client is responsible for visiting the url.
The problem I’m having with this approach is that flash messages are not kept between “fake” redirects. Is there a way to persist flash messages for another request? Or maybe there is a different approach I’m not seeing here.
Just as a side note, unpoly.js is very turbolinks-like, but newer, some more features, and handles redirects fine (you set a header).
As for keeping the flash’es, that is handled by the :fetch_flash plug on your router, you can see its implementation at:
Basically if the status is 300.308 then it puts the flash back, else it deletes it, so if you could set the status that would work, or make your own replacement fetch_flash to detect some kind of assign or so, or PR in an option to persist a flash given some function or so, or a variety of other methods.
Or if you can edit the front-end to look for a special header then do a redirect itself (like unpoly.js does) then that works too.