form_for ArgumentError语言 - 参数数目错误(3 for 1)



我的代码非常简单,但是我不知道错误来自哪里。我正在访问localhost:3000/clients/new,我得到了错误wrong number of arguments (3 for 1)

堆栈顶部跟踪

ArgumentError - wrong number of arguments (3 for 1):
  (gem) actionpack-3.2.12/lib/action_view/helpers/form_helper.rb:378:in `form_for'
  (gem) haml-3.1.8/lib/haml/helpers/action_view_mods.rb:183:in `form_for_with_haml'
  (gem) haml-3.1.8/lib/haml/helpers/xss_mods.rb:132:in `form_for_with_haml_xss'
  app/views/clients/new.html.haml:1:in `_app_views_clients_new_html_haml__386962141__622328728'

/app/controllers/clients_controller.rb

class ClientsController < ApplicationController
  def new
    @client = Client.new
  end
end

/app/模型/client.rb

class Client < ActiveRecord::Base
  attr_accessible :name
end

/app/views/客户/new.html.haml

= form_for @client, remote: true do |f|
  = f.text_field :name
  = f.submit

如果我在form_for前一行检查@client,我得到了这个

=> #<Client id: nil, name: nil, created_at: nil, updated_at: nil>

任何帮助都会很感激。由于

编辑以简化代码

好的,固定。我把答案贴出来,即使它可能对你们大多数人没有用处,但我希望它能帮助一些人。

错误来自于我用一个名为fields_for的函数创建了一个助手。将我的函数名更改为不同的名称可以解决问题。

如果有人能解释一下:

为什么我的自定义fields_for嵌套在我的模块优先于actionpack的fields_for ?

还有为什么堆栈跟踪停止在(gem) actionpack-3.2.12/lib/action_view/helpers/form_helper.rb:378行,而不是显示我的fields_for被声明的行?

最新更新