运行时错误:为用户声明 attr_protected 或 attr_accessible,但不能同时声明两者
由于短时间内我的 Rails 应用程序在测试套件中产生了以下运行时错误:
RuntimeError: Declare either attr_protected or attr_accessible for User, but not both.
这可能是由 Restful_authentication 的更新引入的。但扫描“attr_protected”的代码只显示它从未被调用。那么为什么会出现这个错误消息呢?
我的用户模型只有以下代码:
attr_accessible :login, :email, :name, :password, :password_confirmation, :identity_url
所以应该完全没问题?有什么线索可以在哪里寻找问题吗?搜索google发现有一些无知的人也只在测试环境中看到这个问题,偶尔在开发环境中也看到这个问题。
Since a short time my rails applications yields the following runtime error in the test suite:
RuntimeError: Declare either attr_protected or attr_accessible for User, but not both.
This was probably introduced by an update to restful_authentication. But scanning the code for "attr_protected" only shows me it is never called. So why this error message?
My user model only has the following code:
attr_accessible :login, :email, :name, :password, :password_confirmation, :identity_url
So it should be perfectly okay? Any clues where to look for the problem? Searching google shows a few clueless people who also see this problem only in test environment and sporadically in the development environment.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您将 RestfulAuthentication 与Friendly_id一起使用,最新版本的Friendly_id可能会带来此错误,如github页面所示:
另外,当使用 grep 查找出现的关键字时,不要忘记在 gems 中 grep因为您可能已经安装了一些插件作为 gem 存档。
If you are using RestfulAuthentication with friendly_id, the latest version of friendly_id can bring this error as indicated on the github page:
Also, when using grep to find occurences of keywords, don't forget to grep also in gems as you may have installed some plugins as gem archive.
您可能在声明attr_protected
的User
类中包含
d 个模块。也许某种测试功能可以做到这一点。You might haveinclude
d modules into theUser
class that declareattr_protected
. Maybe some kind of testing functionality does that.这可能是由于插件添加了
attr_protected
。 这可能会有所帮助。This could be due to a plugin adding
attr_protected
. This might be helpful.