I tried:
new.html.erb
<%= turbo_frame_tag "form" do %>
<%= render 'form', course: @course %>
<% end %>
controller:
respond_to do |format|
if @course.save
format.turbo_stream { redirect_to edit_course_path(@course), notice: "Course was successfully created." }
else
format.turbo_stream
end
end
create.turbo_stream.erb
<%= turbo_stream.replace "form" do %>
<%= render "form.html", course: @course %>
<% end %>
This way, I can show form validation errors, but then if the form is successful, it doesn’t redirect properly. I.e I can actually see these two requests happening behind the scenes.
If I don’t wrap the form in the turbo_frame_tag, then redirect works, but how can I then show form errors?
Edit: thanks to https://twitter.com/Intrepidd/status/1341482325280960519, the key is to add frame: “_top” to the turbo_frame_tag. E.g <%= turbo_frame_tag "form", target: "_top" do %>
. Then redirects start to work.