Adding a TOS agreement flag using Devise

We use the program for our members. We added the tos_agreement (boolean) field 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 great - if you do not accept TOS, you cannot register.

However, the problem is with editing your settings. If you go to /members/edit , you will get a form in which you can change your email address or password. There is no field for a TOS agreement, since at this point it should not change. However, when you make changes (for example, change your password) and submit the form, it returns an error message that the TOS agreement cannot be false.

How can we say that we never tried to change the TOS agreement after the first registration?

Edit: so I believe that the main problem was what we had: tos_agreement in our attr_accessible, which was a very bad idea, now I think about it. But if we delete it, how do we modify Devise to accept a parameter and do something with it, even if it is not intended for mass use?

+8
validation ruby-on-rails ruby-on-rails-3 devise
source share
1 answer

You can pass: on =>: create an option in the validator so that it is checked only during registration:

 validates_acceptance_of :tos_agreement, :allow_nil => false, :accept => true, :on => :create 
+15
source share

All Articles