Posted By

garethhrees on 11/30/10


Tagged


Versions (?)

Rails validate before save


 / Published in: Rails
 

  1. class Product < ActiveRecord::Base
  2. validate :must_go_on_sale_before_event_starts
  3.  
  4. # has scheduled_for datetime
  5.  
  6.  
  7. protected
  8. def must_go_on_sale_before_event_starts
  9. errors.add(:scheduled_for, 'should be before starts at') if scheduled_for > behaviour.starts_at || behaviour.starts_at < scheduled_for
  10. end
  11. end
  12.  
  13. class Product::Event < ActiveRecord::Base
  14. # has starts_at datetime

Report this snippet  

You need to login to post a comment.