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 "You have a nil object when you didn't expect it!" 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.
class Person < ActiveRecord::Base
has_many :book_check_outs
has_many :books, :through => :book_check_outs
end
class Book < ActiveRecord::Base
has_many :book_check_outs
has_many :people, :through => :book_check_outs
def checked_out
book_check_outs || false
end
end
class BookCheckOut < ActiveRecord::Base
belongs_to :book
belongs_to :person
end