Call child's method or cast parent to child in Rails
Posted
by Brian
on Stack Overflow
See other posts from Stack Overflow
or by Brian
Published on 2010-03-24T07:00:32Z
Indexed on
2010/03/24
7:03 UTC
Read the original article
Hit count: 477
ruby-on-rails
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
class TypeB
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!
© Stack Overflow or respective owner