title: Ruby on Rails prevent nil error when it is assumed record may not exist
body: <p>I am building a simple book check out application. One of the things that I need to do is determine if a book is checked out. I have my associations between my people and book classes setup through a book_check_out class. My goal is to use the checked_out property of book to determine if a book is presently checked out. However, in my present implementation when a book is not checked out and I reference book.checked_out.XXX I receieve the error "<em>You have a nil object when you didn't expect it!</em>" My goal is to use book.checked_out for two purposes in some views show that yes, that book is checked out and in other views show who it is presently checked out to.</p>
  
  <pre><code>class Person &lt; ActiveRecord::Base
    has_many :book_check_outs
    has_many :books, :through =&gt; :book_check_outs
  end
  </code></pre>
  
  <hr>
  
  <pre><code>class Book &lt; ActiveRecord::Base
  
    has_many :book_check_outs
    has_many :people, :through =&gt; :book_check_outs
  
    def checked_out
      book_check_outs || false
    end
  end
  </code></pre>
  
  <hr>
  
  <pre><code>class BookCheckOut &lt; ActiveRecord::Base
    belongs_to :book
    belongs_to :person
  end
  </code></pre>