未定义的方法`attribute_method_matcher',用于空值:NilClass。

7
我正在遇到这个错误 "undefined method `attribute_method_matcher' for nil:NilClass"。
我的控制器名称是Cad,它的功能是:
  def index
     @cadempty = Cad.new
     @caddata = Cad.all

  end

错误出现在创建新对象时。如果我注释掉Cad.new,代码就能正常工作。
之前我以为可能是因为我有一个名为'new'的方法,我正在使用User.new创建一份空白表单对象。但这不是错误所在,我将方法重命名为其他名称,错误仍然存在。我不知道我做错了什么。

可能是重复问题:http://stackoverflow.com/questions/12414297/how-do-i-analyze-the-source-of-the-undefined-method-attribute-method-matcher - Иван Бишевац
1个回答

7
也许你的数据库表中的某个列名是保留字。

避免在方法命名中使用语言中的保留字。


是的,那就是问题所在...感谢你的帮助。 - Sachin Prasad

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接