if you put a field called type in the table of the base class AR will automaticly save to the correct class, in fact from that moment on everything will behave as is you had 2 models, no need for more configuration.
On Tue, Sep 14, 2010 at 10:20 AM, Frederick Cheung < [email protected]> wrote: > > > On Sep 14, 11:31 am, moonshadow <[email protected]> wrote: > > > How can I write a method within Person that will detect what gender > > has been defined and return the proper object based on it? > > > > I'm thinking something like... > > > > def self.new > > gender_class = self.gender == 'Female' ? 'Female' : 'Male' > > eval(gender_class).new > > end > > > > In that version, though, "self.gender" isn't recognized. I'm sure I'm > > missing something really basic, but can someone point out what it is? > > > > new is a class method, but gender is an instance method. Apart from > that I'm not sure what you're trying to do? Do you know that Active > Record can handle STI for you ? > > Fred > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<rubyonrails-talk%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

