Rails Remote Form does not post form parameters

↘锁芯ラ 提交于 2019-12-12 04:07:39

问题


my question involves the following partial view with a remote form:

 <% remote_form_for :phone_number, :url => {:controller => "edit", :action => "add_phone_number" }, :update => "phone_number_div" do |form| %>
    <%= form.text_field :number%>
    <%= form.select :type, PhoneNumber::PHONE_TYPE%>
    <%= submit_tag "Add" %>     
 <% end %>

When the Add button is pressed, the add_phone_number action is posted to, but the form values are not in the params variable.

Does anyone know why this could be?


回答1:


Most browsers won't pass the form values in the post if the form element is a child node in an illegal location in the DOM (like inside a TR, for example (and not in a TD).

I ran into this problem once.




回答2:


You probably want to have some sort of method for the form.

<% remote_form_for :phone_number, :method => :post, :url => { :controller => "edit", :action => "add_phone_number" }, :update => "phone_number_div" do |form| %>

Not to be picky but if you are using remote_for_form you want to have a resource to use it with. So you would want to replace :phone_number with @phone_number an instance variable that you instantiated in your controller. This keeps the code a little nicer and it is also in keeping with the conventions of Rails.

Also for problems like these debugger is your friend



来源:https://stackoverflow.com/questions/660258/rails-remote-form-does-not-post-form-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!