Blog

Mar
11

Please accept the terms of service and privacy policy

Posted by Michael Cindric in ruby on rails | 3 Comments »

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'

3 Responses

03.11.09

Nice information, I really appreciate the way you presented.Thanks for sharing..

03.11.09

I had to add “attr_accessible :terms_of_service”
to get this to work.

03.11.09

What authentication gem are you using? Authlogic?

Leave Your Response

Name*
Email*
Website URL
Comments*
* Name, Email, Comment are Required
*

Spam Protection by WP-SpamFree