Quick debugging of validations with Rails
Written by Robin Fisher in 88 words
27
Apr
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.