当我在我的 rails 3 项目 gem "simple-captcha" ( https://github.com/galetahub/simple-captcha ) 中使用时,我通过调用函数 <%= show_simple_captcha %> 看到了错误:
Can't mass-assign protected attributes: key
当我在我的 rails 3 项目 gem "simple-captcha" ( https://github.com/galetahub/simple-captcha ) 中使用时,我通过调用函数 <%= show_simple_captcha %> 看到了错误:
Can't mass-assign protected attributes: key
这对我有用:
将其放入初始化程序(config/initializers/simple_captcha.rb)
Rails.configuration.to_prepare do
class SimpleCaptcha::SimpleCaptchaData < ::ActiveRecord::Base
attr_protected
end
end
我收到此错误是因为我使用的是基于表单的视图代码:
<%= f.simple_captcha(:label => "Enter letters from image above", :placeholder => "") %>
我认为这是由 f 引用我的用户模型引起的,该模型无法引用验证码属性。我放弃了表格基地,问题就消失了。(尝试了上述两种解决方案,但在我的情况下它们不起作用。):
<%= show_simple_captcha(:label => "Enter letters from image above",
:placeholder => "") %>
解决方案:使用 Rails 3 应用程序的替代存储库通过
gem 'simple_captcha', :git => 'git://github.com/rubymaniac/simple-captcha'