Rails 3: undefined method `remote_form_for'

偶尔善良 提交于 2019-12-10 12:53:03

问题


I have a fairly simple Rails remote form in HAML in a partial under shared/users:

- remote_form_for :user, :url => { :controller => "users", :action => "create" } do |f|
  .field
    = f.label :name, t('name')
    = f.text_field :name
  .field
    = f.label :email, t('email')
    = f.text_field :email
  .actions
    = f.submit

No matter how much I fiddle with it, this just won't work. I alway get the following error:

undefined method `remote_form_for' for #<#<Class:0x1036e8e40>:0x1036dfd90>

Am I doing something stupid? It works perfectly with form_for.


回答1:


remote_form_for no longer exists.

Try adding

:remote => true

as an option to form_for

form_for :user, :remote => true, :url => { :controller => "users", :action => "create" } do |f|

see: http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-form_for




回答2:


It's because this method is delete on Rails 3

Use now

form_for ..., :remote => true

Your code becomes :

- form_for :user, :url => { :controller => "users", :action => "create" }, :remote => true do |f|
  .field
    = f.label :name, t('name')
    = f.text_field :name
  .field
    = f.label :email, t('email')
    = f.text_field :email
  .actions
    = f.submit

And you need the rails.jquery.js or same in prototype to use it. It's the UJS improvement in rails.



来源:https://stackoverflow.com/questions/3890315/rails-3-undefined-method-remote-form-for

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