validate with errors


/ Published in: Ruby
Save to your folder(s)

validate :price_must_be_at_least_a_cent
protected def price_must_be_at_least_a_cent
errors.add(:price, 'should be at least 0.01') if price.nil? || price < 0.01
end


Copy this code and paste it in your HTML
  1. validate :price_must_be_at_least_a_cent
  2.  
  3. protected
  4. def price_must_be_at_least_a_cent
  5. errors.add(:price, 'should be at least 0.01') if price.nil? || price < 0.01
  6. end

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.