Call child's method or cast parent to child in Rails
- by Brian
I have some STI structure like following:
class Box
has_many :part,:class_name = "Part"
end
class Part
def self.dosomething()
end
end
class TypeA<Part
def self.dosomething()
end
end
class TypeB<Part
def self.dosomething()
end
end
assuming we have some codes like boxtypeA = Box.new. I am wondering if there is a way to make boxtypeA.part.dosomething() to call TypeA's method not Part's or TypeB's. I think basically what we need to do is to convert the part to TypeA, how can we achieve that?
Thx in advance!