I am trying to create inline editing in a rails 3.1 project. I am creating the form to edit the copy via ajax, then trying to send the edit via ajax as well.
However the form does not want to bind and form will not submit on the forms created via ajax.
does anyone now how to bind the form after it’s created
I use edit.js.erb to add the form:
$("#nutri_<%= @nutritioninfo.id %>").after('<%= escape_javascript(render(:partial=>'admin/products/nutrition_edit', :locals=>{:nutritioninfo=>@nutritioninfo}))%>');
and the partial is like so:
$%tr.hidden.edit-nutri{ :class => cycle('odd', 'even', :name => "nutrition-hidden-rows"), :id=>"nutri_edit_#{nutritioninfo.id}" }
= simple_form_for [:admin,site,product,nutritioninfo], :remote=>true do |f|
%td
%td= f.input :title,:label => false
%td= f.input :parent_id, :as=>:select, :collection=>nutritioninfo.possible_parents,:label => false
%td= f.input :per100g, :label => false
%td= f.input :info, :label => false
%td= f.input :highlight,:as=>:boolean, :label => false
%td.edit= f.button :submit, t('admin.general.save').humanize
%td.remove=link_to t('admin.general.cancel').humanize, "#", :remote => true, :class=>"cancel-toggle"
Anyone have an idea on how to bind the form?
There could be few issues.
First of all, maybe obvious but do you require jquery_ujs in application.js? If you don’t have any actions with remote: true, it could be the reason.
Second does it even trigger the submit on form? Remember that when using ajax you must use ‘live()’ instead of ‘bind()’ or ‘action()’ because live will make bind on elements each time you reload the form (‘bind’ binds action only once).
But if the submit goes on, and you don’t have any respond, then you probably must implement xhr request in controller just like Andre Dublin said.
Good art on rails with ajax you could refer to Using Unobtrusive JS and AJAX with Rails 3 also maybe you should take a look at In place editing RailsCast ?