Switching from form_for to remote_form_for problems with submit changes in Rails
- by Matthias Günther
Hi there,
another day with Rails and today I want to use Ajax. linkt_remote_link for changing a text was pretty easy so I thought it would also be easy to switch my form_for loop just to an ajax request form with remote_form_for, but the problem with the remote_form_for is that it doesn't save my changes?
Here the code that worked:
<% form_for bill, :url => {:action => 'update', :id => bill.id} do |f| %>
# make the processing e.g. displaying texfields and so on
<%= submit_tag 'speichern'%>
It produces the following html code:
<form action="/adminbill/update/58" class="edit_bill" id="edit_bill_58" method="post"><div style="margin:0;padding:0;display:inline"><input name="_method" type="hidden" value="put" /></div>
<!-- here the html things for the forms -->
<input class="button" name="commit" type="submit" value="speichern" />
Here the code which don't save me the changes and submit them:
<% remote_form_for bill, :url => {:action => 'update', :id => bill.id} do |f| %>
# make the processing e.g. displaying texfields and so on
<%= submit_tag 'speichern'%>
It produces the following html code:
<form action="/adminbill/update/58" class="edit_bill" id="edit_bill_58" method="post" onsubmit="$.ajax({data:$.param($(this).serializeArray()), dataType:'script', type:'post', url:'/adminbill/update/58'}); return false;"><div style="margin:0;padding:0;display:inline"><input name="_method" type="hidden" value="put" /></div>
<!-- here the html things for the forms -->
<input class="button" name="commit" type="submit" value="speichern" />
I don't know if I have to consider something special when using remote_form_for (see remote_form_for)