Hello,
I’ve got a problem with the inheritance as soon as I try to use it in a
model.
I’ve got plenty of items which can share a lot of code, so I created a
class “Item”, which inherits from ActiveRecord::Base, but because it’s
not a “real item” but an interface, I set it abstract (writing
abstract_class? method).
Then I have all the differents items I can use (for instance:
book,picture,…) which have their own class.
I tried to write it down like :
class Item < ActiveRecord::base
def abstract_class?
true
end
#stuff
end
class Book < Item
def abstract_class?
false
end
#stuff
end
The problem is, when I call Book.new.title I get an error saying that
the method doesn’t exist (even if Book table has got a title column),
and if I try Book.find(:first).title, it works…
I’ve got the impression that Book.new returns an Item instead of a Book
… Does anyone know how to fix my problem?
Thanks a lot