Turbo morph with same page redirect

I’m trying to get turbo morph to work for controller that calls redirect_to request.referer, ie. the current page. The reason I’m using request.referer is that the controller in question handles requests to add/edit/delete filters on several sub-tables of a larger object, meaning it can make requests from many different “pages” which to the user are just different tabs with different URLs.

I’ve made sure to add <%= turbo_refreshes_with method: :morph, scroll: :preserve %> to my application.html.erb, but I’m struggling to get turbo morph working with this setup, so I’m wondering if it’s even possible with request.referer, or if there is something else I’m missing?

From what you wrote it seems like it should work. It’s hard to tell without seeing the full app why exactly morphing is not being selected.

However, this should be fairly easy to debug, there’s only one place in Turbo source where the logic for whether morphing or replacing of body will be done, it’s in PageView#renderPage method: turbo/src/core/drive/page_view.js at main · hotwired/turbo · GitHub

If I were you, I’d start by placing a breakpoint there and seeing what the conditions are evaluating to.

By chance, I recently wrote up some tips on how to debug morphing issues, maybe you also find that useful: How to debug issues with Turbo Morphing | Radan Skorić's personal site

1 Like