captured sparks

Quick debugging of validations with Rails

In an application I’m building, I have a tricky validation that needs to ensure that a booking created by the user:

  1. is not entirely within an existing booking
  2. does not have a start time within an existing booking
  3. does not have an end time within an existing booking
  4. does not span an existing booking

While testing the validation, it was really useful to add the following to the validation code:

existing_bookings.each do |b|
  Rails.logger.debug("#{b.id} - #{b.from} - #{b.to}")
end

This was valuable in identifying what bookings my AR query was pulling out during the validation.

You can talk to me, or trackback from your own site. Or, if you're looking for more things to read? Why not check out the Archive.

Talk to me