We're using devise for our members. We've added a tos_agreement field (boolean) to our member schema, and we added it to views/devise/registrations/new.html.haml
.
In the Member model, we have a validation rule as follows:
validates_acceptance_of :tos_agreement, :allow_nil => false,
:accept => true
It works fine - if you don't accept the TOS, you can't register.
However, the problem comes with editing your settings. If you go to /members/edit
you get the form where you can change your email address or password. There's no field for the TOS agreement since this shouldn't be changeable at this point. However, when you make a change (eg. change your password) and submit the form, it returns an error message that the TOS agreement can't be false.
How can we tell it never to attempt to modify the TOS agreement after the first registration?
Edit: so I think the fundamental problem is that we had :tos_agreement in our attr_accessible, which was a very bad idea now I think of it. But if we remove it, how do we modify Devise to accept the parameter and do something with it even though it's not mass-assignable?
You can pass an :on => :create option to the validator so that it's only checked on signup:
validates_acceptance_of :tos_agreement, :allow_nil => false, :accept => true, :on => :create
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With