Rails Form Redirect Not Rendering HTML
Recently our login and sign up forms on Do Every Day broke. After submitting the forms, it appeared to the user that the same form page reloaded and you did not get logged in or signed up. Reloading the page the user would discover that they were indeed logged in, but who actually did that? This was especially unfortunate because Do Every Day had just been featured on this Google blog post.
I believe things broke along the way as I upgraded Rails and the turbo-rails gem, generally for security updates. Turbo is relatively new and has been changing rapidly. While I have a decent test suite on the Do Every Day repo, I had yet to dip into system (browser) tests. This particular problem could only be caught by such tests.
What I discovered was all of the problems were with three forms that were supposed to be redirecting to the page that shows a user: login, sign up, and edit profile. Each of
forms were just HTML requests, but Turbo Drive takes over and submits all of these forms as the format
In this case I had two views for the users/show page:
show.turbo_stream.erb. At some point in those aforementioned upgrades to Rails/Turbo had become
strict and no longer understood these basic form-redirects as HTML formats. TURBO_STREAM in, TURBO_STREAM out.
Once tests were working, I went on a deep Duck Duck Go excursion trying to figure out why Rails was doing this
After a couple of hours of searching and troubleshooting I discovered that Rails now needs you to be explicit about
leaving Turbo Drive with
Suddenly tests were passing, both automated and clicky.
Hopefully over the next year or so this blog post pops up for anyone who is looking to fix the same problem.