Rails 3:未定义方法“remote_form_for”

发布于 2024-09-26 23:55:58 字数 512 浏览 8 评论 0原文

我在共享/用户下的部分 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

无论我如何摆弄它,这都行不通。我总是收到以下错误:

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

我在做一些愚蠢的事情吗?它与 form_for 完美配合。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦与时光遇 2024-10-03 23:55:58

Remote_form_for 不再存在。

尝试添加

:remote => true

为 form_for 的选项,

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

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

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

青衫负雪 2024-10-03 23:55:58

这是因为这个方法在Rails 3上被删除,

现在使用

form_for ..., :remote => true

你的代码变成:

- 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

并且你需要rails.jquery.js或原型中的相同方法才能使用它。这是UJS对铁轨的改进。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文