Validate method also accepts :on and :if parameters. The
default value for :on is :save, the other accepted values
are :create and :update

class CommentincludeActiveModel::Validationsvalidate:must_be_friends,:on=>:create,:if=>Proc.new{|comment|some_condition}def must_be_friendserrors.add(:base,"Must be friends to leave a comment")unlesscommenter.friend_of?(commentee)endend

This is a very useful method if you want to to use a scope through an
association:

class Book<ActiveRecord::Basescope:available,where(:available=>true)endclass Author<ActiveRecord::Basehas_many:booksscope:with_available_books,joins(:books).merge(Book.available)end# Return all authors with at least one available book:Author.with_available_books