Subscribe
Contact



AddThis Social Bookmark Button
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

Commentaires :
Andrew Degenhardt , Fri Aug 01 08:58:20 +0200 2008
if anyone is wondering about how to get the error message to show in the view here it is:



I spent some time trying to find the answer to this one
#1
Andrew Degenhardt , Fri Aug 01 08:59:35 +0200 2008
i had to take out the surrounding symbols because they didnt show, maybe the author can fix this

= error_messages_for 'model_name_goes_here'
#2

Add a comment :





© 2007 Eric Abouaf