Posted By

stayce on 04/30/10


Tagged

rails ruby validate


Versions (?)

validate with errors


 / Published in: Ruby
 

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

  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  

You need to login to post a comment.