Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't mass-assign protected attributes: captcha, captcha_key #49

Open
ghost opened this issue Feb 1, 2016 · 3 comments
Open

Can't mass-assign protected attributes: captcha, captcha_key #49

ghost opened this issue Feb 1, 2016 · 3 comments

Comments

@ghost
Copy link

ghost commented Feb 1, 2016

ruby 1.9.3, rails 3.2.19

Error

Can't mass-assign protected attributes: captcha, captcha_key

To fix this have added attr_accessible into User model.

attr_accessible :captcha, :captcha_key

And now its allowing me to register with wrong captcha as well

@sagarjunnarkar
Copy link

Hello @rohit-clarion
I also faced same issue when I tried model based flow.
Added captcha, captcha_key in attr_accessible and added custom validation.
Now valid_with_captcha calls valid method and that produces error SystemStackError: stack level too deep so I used is_captcha_valid?

validate :check_captcha, on: :create
  def check_captcha
      unless is_captcha_valid?
           #Remove wrong message : Captcha translation missing: en.simple_captcha.message.user
           errors[:captcha].try(:pop)
           errors.add :captcha, "does not matched"
       end
  end

Here is user model.

@ghost
Copy link
Author

ghost commented Feb 2, 2016

@sagarjunnarkar thank you

@sapna-prajapati
Copy link

I had face the same issue and traversing through infinite loop while applied custom validation. Thanks for correction @sagarjunnarkar. Good Job.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants