I have an abstract Base class. Let’s call it Animal::Base.
module Animal
class Base < ActiveRecord::Base
self.abstract_class = true # so that Rails won't think this is in STI-mode
ordered_tree
end
end
ordered_tree just applies the OrderedTree gem to the class that invokes the method:
belongs_to :parent_node, :class_name => name, ...
It gets the name of the class that it is applied to. However, name at this point is Animal::Base, but I want it to be whatever inherits the Animal::Base class instead:
class Dog < Animal::Base
end
In this case, I want the parent_node to refer to the Dog class (effectively applying belongs_to :parent_node, :class_name => "Dog", ...), not Animal::Base. Is this possible?
You may have to put your ordered_tree call in the Dog class. There is also the self.included method, but that runs everything within the scope of the parent class, though it passes in the child class as a parameter. So, maybe you could do something like:
I haven’t tried this myself and suspect you may run into the same problem (ordered_tree still running in context of Base) but it’s worth a shot…