Note that there are some explanatory texts on larger screens.

plurals
  1. POSubmit tow forms with jquery rails
    primarykey
    data
    text
    <p>Ok my issue is simple, i have two very, very similar forms on one view, only the id makes the difference:</p> <pre><code>&lt;table width="100%"&gt; &lt;tr&gt; &lt;%= form_for ([@patient, @patient.treatments.build]),:html =&gt; { :id =&gt; "my_form2" } do |f|%&gt; &lt;th&gt;&lt;%= f.collection_select :category_id, Category.find(:all), :id, :typ %&gt;&lt;/th&gt; &lt;th&gt;&lt;%= f.text_field :content %&gt;&lt;/th&gt; &lt;th&gt;&lt;%= f.hidden_field :note, :id =&gt; "canvascontent" %&gt;&lt;/th&gt; &lt;th&gt;&lt;%= f.text_field :day, :value =&gt; Date.today %&gt;&lt;/th&gt; &lt;th&gt;&lt;input type="button" value="Speichern" class = "btn btn-small btn-primary" id = "button1" onclick="sketch.toDataURL()"&gt;&lt;/th&gt; &lt;th&gt;&lt;input type="button" onclick="sketch.clearRecording()" class="btn btn-small btn-danger" value="Löschen"&gt;&lt;/th&gt; &lt;% end %&gt; &lt;/tr&gt; &lt;/table&gt; &lt;table width="100%"&gt; &lt;tr&gt; &lt;%= form_for ([@patient, @patient.treatments.build]),:html =&gt; { :id =&gt; "my_form1" } do |f|%&gt; &lt;th&gt;&lt;%= f.hidden_field :category_id, :value =&gt; findems(Ebm) %&gt;&lt;/th&gt; &lt;th&gt;&lt;%= f.hidden_field :content , :id =&gt; "inputbox"%&gt;&lt;/th&gt; &lt;th&gt;&lt;%= f.hidden_field :day, :value =&gt; Date.today %&gt;&lt;/th&gt; &lt;% end %&gt; &lt;/tr&gt; &lt;/table&gt; </code></pre> <p>And i want to trigger the submit of both with only one submit button, so i created an button:</p> <pre><code>&lt;input type="button" value="Speichern" class = "btn btn-small btn-primary" id = "button1" onclick="sketch.toDataURL()" </code></pre> <p>And to trigger the submit of the both forms at the same time an jquery function:</p> <pre><code>$(document).ready(function() { $("#button1").click(function(){ $('#my_form1').trigger('submit'); $('#my_form2').trigger('submit'); }); </code></pre> <p>But it wont work, rails always only saves that form that is first triggerd in my function, in this case #my_form1. I think my controller is to blame because after the first is saved it redirects to another site so that the second form isnt saved. But im Rails beginner and dont know how to ovewerite this behaviour. My controller:</p> <pre><code> def create @patient = Patient.find(params[:patient_id]) @treatment = @patient.treatments.create(params[:treatment]) redirect_to patient_path(@patient) end </code></pre> <p>I tried to simply remove the last line of my controller but then i get the error:</p> <pre><code> Missing template treatments/create, </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload