A reusable respond_to block for turbo_stream + html

2687
0

Once you’ve built a few Hotwire controllers, you notice the same respond_to shape repeated. I extract a small helper (a concern) that yields a respond_to block and centralizes the “default HTML redirect” pattern. This keeps controllers readable and reduces subtle inconsistencies (like returning 200 instead of 422 on invalid). The trick is not to hide too much—controllers still decide which template to render—but you can standardize status codes and fallbacks. I also like to use this to enforce status: :see_other for redirects. It’s a small refactor that pays back quickly as the app grows.