RuntimeError:为User声明attr_protected或attr_accessible,但不是两者都声明

hur*_*n77 3 unit-testing ruby-on-rails restful-authentication

由于我的rails应用程序在短时间内在测试套件中产生以下运行时错误:

RuntimeError: Declare either attr_protected or attr_accessible for User, but not both.
Run Code Online (Sandbox Code Playgroud)

这可能是由restful_authentication的更新引入的.但是扫描代码"attr_protected"只会告诉我它永远不会被调用.那么为什么会出现这个错

我的用户模型只有以下代码:

attr_accessible :login, :email, :name, :password, :password_confirmation, :identity_url
Run Code Online (Sandbox Code Playgroud)

那应该是完全可以的吗?有什么线索在哪里寻找问题?搜索谷歌显示了一些无知的人,他们也只在测试环境中看到这个问题,偶尔也会在开发环境中看到这个问题.

小智 6

如果您对friendly_id使用RestfulAuthentication,则最新版本的friendly_id可能会在github页面上显示此错误:

此外,此功能使用attr_protected来保护cached_slug列,除非您已经调用了attr_accessible.因此,如果您希望使用attr_accessible,则必须在调用类中的has_friendly_id之前调用它. github页面

此外,当使用grep查找关键字的出现时,不要忘记在gems中使用grep,因为您可能已经安装了一些插件作为gem archive.