【发布时间】:2014-03-11 13:23:06
【问题描述】:
当我在我的 rails 3 项目 gem "simple-captcha" (https://github.com/galetahub/simple-captcha) 中使用时,我通过调用函数 看到了错误:
Can't mass-assign protected attributes: key
【问题讨论】:
标签: ruby-on-rails-3 simplecaptcha
当我在我的 rails 3 项目 gem "simple-captcha" (https://github.com/galetahub/simple-captcha) 中使用时,我通过调用函数 看到了错误:
Can't mass-assign protected attributes: key
【问题讨论】:
标签: ruby-on-rails-3 simplecaptcha
这对我有用:
将其放入初始化程序 (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'
【讨论】: