I have a form in my app where users can bulk edit some tag names.
Once the operation is finished, I would like to display a page featuring all concrete changes to these records.
When using Turbo, it requires me to redirect to some other page after form submission instead of rendering a regular HTML page with status code 200.
My setup is pretty much like this:
# config/routes.rb
resources :tags do
collection do
get "bulk-edit"
# use same path to prevent RoutingError in case of refresh
post :bulk_update, path: "bulk-edit"
end
end
<%# app/views/tags/bulk_update.html.erb %>
<%- @bulk_edit_tags.tags.each do |tag| %>
<%= tag.name_before_last_save %> -> <%= tag.name %>
<%- end -%>
The main problem with redirection is, I cannot display the old tag name easily.
Using a Turbostream-response in my case is also not feasible.
Would it be best to disable Turbo for this singular form submission or are there any major downsides to this that I am missing?
Is the approach I am intending (displaying an ephemeral HTML page) a “clean” solution or does anybody know of a way to improve this approach?
Well, I’m no expert, but I think this is exactly the kind of case where you would disable Turbo for the request, and return a good old HTTP full-page response. The one disadvantage I’m aware of is that the URL in the browser bar will continue to be the URL of the POST request, but that’s true any time you render from a form submission.
Another option besides disabling Turbo: keep the redirect (post/redirect/get) and persist the result of the bulk edit so the next page can show it. For example, collect the before/after pairs while you save, e.g. `changes = tags.map { |t| [t.name_was, t.name] }`, then store them on a small BulkEdit record (or a JSON column) and `redirect_to bulk_edit_path(record)`. The show page reads the stored pairs, so a refresh or the back button works too, and you don’t end up with a page living at a POST URL. If it’s truly throwaway data, a short `flash[:bulk_changes]` works for small lists, but cookie session storage is limited to about 4 KB, so avoid it for large batches. Disabling Turbo with `data: { turbo: false }` is fine for a one-off, just be aware of the refresh issue.