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:
- is not entirely within an existing booking
- does not have a start time within an existing booking
- does not have an end time within an existing booking
- 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.
If you enjoyed this post, you should sign up to be notified when my book, Real World Development with Ruby on Rails, is released in May 2013. The book and full source code to the application we develop in it will be just $39 with added value packages also available.


