Rails, Turbo-frames, how to make turbo response just simply refresh the current view?

664 Views Asked by At

The situation: I have a form partial that I want to use in two separate pages. After submit I want to update another part of the page with the newly added items but those differ depending of which page I'm on. Hence I can't rely on one single response from the controller to satisfy both types of targets. One is a table (which is hell to update with turbo-frames), the other is just a list.

Question: How to do this in shortest way possible?

My current solution to this is to pass a hidden field into with a custom redirect_to value being set as a local variable on the form

page.html.haml:

= render 'prescriptions/form', redirect_value: request.original_fullpath

_form.html.haml:

= form_with model: @prescription, url:[@patient, @prescription] do |f|
      = hidden_field_tag :redirect_to, redirect_value

prescription_controller.rb


      if @prescription.save 
        respond_to do |format|
          redirect_to params[:redirect_to] || patient_prescriptions_url(@patient), notice: "Prescription was successfully created."

At least I found this to be a hack to let turbo-frames "run the show" but still just lazy refresh the whole page w/o building specific frames and logic to determine what the controller should return. I guess I'm totally missing some obvious thing here so please educate me!

0

There are 0 best solutions below