Thursday, February 25, 2010

validates_associated


You should use this helper when your model has associations with other models and they also need to be validated. When you try to save your object, valid? will be called upon each one of the associated objects.

class Library <> has_many :books validates_associated :books end

This validation will work with all of the association types.

Don’t use validates_associated on both ends of your associations, they would call each other in an infinite loop.

The default error message for validates_associated is “is invalid”. Note that each associated object will contain its own errors collection; errors do not bubble up to the calling model.

0 comments:

Post a Comment

post answers

 

Copyright 2008 All Rights Reserved Revolution Two Church theme by Brian Gardner Converted into Blogger Template by Bloganol dot com