Model validation with Rails

![Ruby On Rails]( Rails has very nice features to validate a model (directly mapped on your database). However it gets sometimes sloppy if you don't know the exact command to do your validation.Here's a trick I had a hard time to find.
Everybody knows how to validate the uniqueness of a field in a database :
validates_uniqueness_of :date
If you now want to validate the uniqueness of a couple (ex: date,user_id) here's how you can:
validates_uniqueness_of :date, :scope => :user_id

Tags : ,
Categories : Software, Ruby on Rails


comments powered by Disqus
Copyright © 2000-2022 - Eric Abouaf