It seems like eveyone has this problem but no one has a laymans terms answer or even a proper solutions.
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.
I hope someone has a great answer out there... btw im new to rails. code:
index.html.erb
<h1>SSCC</h1>
<div id="orderline_form">
<%= render 'form' %>
</div>
<ul id="orderlines">
<%= render :partial => @orderlines.reverse %>
</ul>
_form.html.erb
<%= form_for(@orderline, :remote => true) do |f| %>
<div class="field">
<%= f.label :Order_ID %>
<%= f.text_field :order_id %><br/>
<%= f.label :SSCC %>
<%= f.text_field :sscc %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
_order_line.html.erb
<%= content_tag_for(:li, order_line) do %>
<%= order_line.id %> |
<%= order_line.order_id %> |
<%= order_line.sscc %>
(<%= link_to 'Delete', order_line, :confirm => 'Are you sure?',
:method => :delete, :remote => true %>)
<% end %>
create.js.erb
$('#orderlines').prepend('<%= escape_javascript(render(@orderline))%>');
$('#orderlines > li:first ').effect('highlight', {}, 3000);
$('#orderline_form > form')[0].reset();
destroy.js.erb
$('#<%= dom_id(@orderline) %>').css('background', 'red');
$('#<%= dom_id(@orderline) %>').hide("fade", {}, 1500);