When I used in my rails 3 project gem "simple-captcha" (https://github.com/galetahub/simple-captcha) I had error in view by calling function <%= show_simple_captcha %>:
Can't mass-assign protected attributes: key
When I used in my rails 3 project gem "simple-captcha" (https://github.com/galetahub/simple-captcha) I had error in view by calling function <%= show_simple_captcha %>:
Can't mass-assign protected attributes: key
THIS WORKED FOR ME:
Put this in an initializer (config/initializers/simple_captcha.rb)
Rails.configuration.to_prepare do
class SimpleCaptcha::SimpleCaptchaData < ::ActiveRecord::Base
attr_protected
end
end
I was getting this error because I was using form-based view code:
<%= f.simple_captcha(:label => "Enter letters from image above", :placeholder => "") %>
I think this was caused by the f referring back to my user model, which could not reference the captcha attributes. I dropped the form base and the problem went away. (Tried both solutions above, but they didn't work in my case.):
<%= show_simple_captcha(:label => "Enter letters from image above",
:placeholder => "") %>
Solution: use alternative repository for rails 3 applications via
gem 'simple_captcha', :git => 'git://github.com/rubymaniac/simple-captcha'