In my code, Author has_many Books, so I could do something like:
If the author has no books, when
@author.books is called, I'd like a default book object with that author's info already filled out (i.e. author_id), something like:
class Author < ActiveRecord::Base
the_books || default_book
That's obviously not real code, but it demonstrates what I'm trying to do.
class Author < ActiveRecord::Base has_many :books alias :__books__ :books def books result = __books__ result.empty? ? default_books : result end private def default_books # ... end end