4

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
Voldemar Duletskiy
  • 981
  • 1
  • 11
  • 30

3 Answers3

2

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
imsinu9
  • 760
  • 7
  • 12
0

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 => "") %>
Don Law
  • 1,329
  • 13
  • 7
-2

Solution: use alternative repository for rails 3 applications via

gem 'simple_captcha', :git => 'git://github.com/rubymaniac/simple-captcha'
Voldemar Duletskiy
  • 981
  • 1
  • 11
  • 30