Posts Tagged ‘validations’

Rails, migrations and validations

Friday, May 9th, 2008

Well, it was a busy day for me in Ruby on Rails land. After picking up on a few new requirements for a project I’m working on (Agile Development rocks eh?), I’ve decided to refactor a lot of the existing codebase to make it a bit cleaner and, while I was at it, migrate the project to Rails 2. It wasn’t hard or very time consuming, thanks to Ben’s tips, since it took me about 20 minutes to go through the offending lines.

One of the things I was able to extract from that refactoring was validations. Some models have to validate data that can’t be validated by a simple regular expression, and since these validations are specific in Portugal, I thought I’d share them with the portuguese Ruby on Rails developers. You can grab them following the link in the end of the post. After dropping the file on your project’s lib folder, all you have to do is add the following line to your environment.rb file:

RAILS_ROOT/config/environment.rb
  1. require 'validations'

And you’ll be ready to go. Documentation is included in the file (in Portuguese). Feedback is appreciated.

Download ActiveRecord validators for Portugal