运行时错误:为用户声明 attr_protected 或 attr_accessible,但不能同时声明两者

发布于 2024-08-10 05:32:59 字数 468 浏览 3 评论 0原文

由于短时间内我的 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 技术交流群。

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

发布评论

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

评论(3

春庭雪 2024-08-17 05:32:59

如果您将 RestfulAuthentication 与Friendly_id一起使用,最新版本的Friendly_id可能会带来此错误,如github页面所示:

此外,此功能使用 attr_protected 来保护 cached_slug 列,除非您已经调用了 attr_accessible。因此,如果您希望使用 attr_accessible,则必须在调用类中的 has_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, this feature uses attr_protected to protect the cached_slug column, unless you have already invoked attr_accessible. So if you wish to use attr_accessible, you must invoke it BEFORE you invoke has_friendly_id in your class.
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.

单身情人 2024-08-17 05:32:59

您可能在声明 attr_protectedUser 类中包含d 个模块。也许某种测试功能可以做到这一点。

You might have included modules into the User class that declare attr_protected. Maybe some kind of testing functionality does that.

淤浪 2024-08-17 05:32:59

这可能是由于插件添加了 attr_protected可能会有所帮助。

This could be due to a plugin adding attr_protected. This might be helpful.

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