Note that there are some explanatory texts on larger screens.

plurals
  1. POJquery Rails 3... form submits twice... deletes twice... help
    primarykey
    data
    text
    <p>It seems like eveyone has this problem but no one has a laymans terms answer or even a proper solutions.</p> <p>I have a form that uses ajax to submit the form and automatically adds it to the list below the text field. The form submits twice so i have two identical (apart form the ID) records. Worse still is when you try to delete it wont renew the page because its tried to delete the same record twice.</p> <p>I hope someone has a great answer out there... btw im new to rails. code:</p> <p>index.html.erb</p> <pre><code>&lt;h1&gt;SSCC&lt;/h1&gt; &lt;div id="orderline_form"&gt; &lt;%= render 'form' %&gt; &lt;/div&gt; &lt;ul id="orderlines"&gt; &lt;%= render :partial =&gt; @orderlines.reverse %&gt; &lt;/ul&gt; </code></pre> <p>_form.html.erb</p> <pre><code>&lt;%= form_for(@orderline, :remote =&gt; true) do |f| %&gt; &lt;div class="field"&gt; &lt;%= f.label :Order_ID %&gt; &lt;%= f.text_field :order_id %&gt;&lt;br/&gt; &lt;%= f.label :SSCC %&gt; &lt;%= f.text_field :sscc %&gt; &lt;/div&gt; &lt;div class="actions"&gt; &lt;%= f.submit %&gt; &lt;/div&gt; &lt;% end %&gt; </code></pre> <p>_order_line.html.erb</p> <pre><code>&lt;%= content_tag_for(:li, order_line) do %&gt; &lt;%= order_line.id %&gt; | &lt;%= order_line.order_id %&gt; | &lt;%= order_line.sscc %&gt; (&lt;%= link_to 'Delete', order_line, :confirm =&gt; 'Are you sure?', :method =&gt; :delete, :remote =&gt; true %&gt;) &lt;% end %&gt; </code></pre> <p>create.js.erb</p> <pre><code>$('#orderlines').prepend('&lt;%= escape_javascript(render(@orderline))%&gt;'); $('#orderlines &gt; li:first ').effect('highlight', {}, 3000); $('#orderline_form &gt; form')[0].reset(); </code></pre> <p>destroy.js.erb</p> <pre><code>$('#&lt;%= dom_id(@orderline) %&gt;').css('background', 'red'); $('#&lt;%= dom_id(@orderline) %&gt;').hide("fade", {}, 1500); </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.
 

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