Displaying 1 result from an estimated 1 matches for "author_without_lookup".
2009 Aug 17
1
Problem with setter override on ActiveRecord
...ups.google.com/group/rubyonrails-talk/browse%5Fthread/thread/4fe057494c6e23e8,
so finally I could had some working code:
class Book < ActiveRecord::Base
belongs_to :author
def author_with_lookup=(author)
author = Author.find_or_initialize_by_name(author) if author.is_a?
String
self.author_without_lookup = author
end
alias_method_chain :author=, :lookup
end
This time, the console was nice to me:
>> book = Book.new(:name => "Alice''s Adventures in Wonderland", :pub_year => 1865)
=> #<Book id: nil, name: "Alice''s Adventures in Wonderland",...