Please accept the terms of service and privacy policy

11 Mar 2009, by Michael Cindrić

If you need users the accept the terms of services and privcay policy or your rails application there is a simple way to handle this without a database field or javascript. It's using the validation methods built into rails. Simply add the following code to your User model for example

validates_acceptance_of :terms_of_service

Then in your view add the following to your view and you will get a checkbox on the page that users will be required to check.

<%= check_box :user, :terms_of_service %>

This will then add this validation rule to your models validation rules and when you try to submit the form without checking the checkbox you get a nice little validation message letting you know hey you need to accept this.

Of course you can have your own validation message displayed like so

validates_acceptance_of   :terms_of_service, :message => ' and the privacy policy must be accepted'


Cookies help us deliver our services. By using our services, you agree to our use of cookies.