Skip to content

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.

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.

No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 168 other followers