Flowdock

Notes posted by ggarnier

RSS feed
May 28, 2012
0 thanks

Accepted parameters for validate

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

class Comment
  include ActiveModel::Validations

  validate :must_be_friends, :on => :create, :if => Proc.new {|comment| some_condition}

  def must_be_friends
    errors.add(:base, "Must be friends to leave a comment") unless commenter.friend_of?(commentee)
  end
end