Rails 3.1 and ajax created forms are not submitted

I am trying to create inline editing in a rails 3.1 project. I create a form to edit a copy via ajax, and then try to submit the edit using ajax.

However, the form does not want to contact and the form will not be submitted to forms created through ajax.

now anyone can link the form after creating

I use edit.js.erb to add a form:

$("#nutri_<%= @nutritioninfo.id %>").after('<%= escape_javascript(render(:partial=>'admin/products/nutrition_edit', :locals=>{:nutritioninfo=>@nutritioninfo}))%>'); 

and partial - like this:

 $%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 &nbsp; %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" 

Does anyone have an idea on how to link a form?

+4
source share
2 answers

There can be no problems.

First of all, perhaps obviously, but do you need jquery_ujs in application.js? If you have no actions with remote: true, this may be the reason.

Secondly, does it even cause form submission? Remember that when using ajax you should use "live ()" instead of "bind ()" or "action ()", because live will create a binding to the elements each time the form is reloaded ("bind" binds the action only once) .

But if the feed continues and you have no answer, then you probably should implement the xhr request in the controller, as Andre Dublin said.

Good art on rails with ajax, you can refer to Using Unobtrusive JS and AJAX with Rails 3 Also, maybe you should take a look at In-Place RailsCast Editing ?

+1
source

Just like Leszek says in the second paragraph: "Remember that when using ajax you should use" live () "instead of" bind () "or" action () ", because live will create a binding to the elements every time, when you reload the form ('bind' binds the action only once). "

0
source

All Articles