Hacker News new | ask | show | jobs
by JFlash 3827 days ago
The validity of an object depends on the observer. If you require all Customers to have a billing address but a person is in the middle of a multi-page checkout, should their Customer record be invalid if they've only filled in their email so far? What if they want to come back to the form later?

Rails tries to fix this with the `:on` option for validations (http://api.rubyonrails.org/classes/ActiveModel/Validations/C...), which goes woefully unused in Rails apps.

Now you can do:

  customer.save(context: :checking_out)
  # which is different than
  customer.save