I have a fairly simple Rails remote form in HAML in a partial under shared/users:
我在HAML中有一个相当简单的Rails远程表单,部分在共享/用户之下:
- 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.
我做了些蠢事吗?它与form_for完美配合。
2 个解决方案
#1
23
remote_form_for no longer exists.
remote_form_for不再存在。
Try adding
尝试添加
:remote => true
as an option to form_for
作为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
请参阅:http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-form_for
#2
1
It's because this method is delete on Rails 3
这是因为这个方法在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.
并且您需要rails.jquery.js或原型中的相同才能使用它。这是UJS在铁轨方面的改进。
#1
23
remote_form_for no longer exists.
remote_form_for不再存在。
Try adding
尝试添加
:remote => true
as an option to form_for
作为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
请参阅:http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-form_for
#2
1
It's because this method is delete on Rails 3
这是因为这个方法在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.
并且您需要rails.jquery.js或原型中的相同才能使用它。这是UJS在铁轨方面的改进。