for a single-table inheritance in rails, how do I know the 'type' when creating a record?
        Posted  
        
            by Angela
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Angela
        
        
        
        Published on 2010-05-26T05:33:58Z
        Indexed on 
            2010/05/26
            5:41 UTC
        
        
        Read the original article
        Hit count: 365
        
ruby-on-rails
|single-table-inheritance
I have several models which are very similar: Contact_Emails, Contact_Letters, Contact_Calls -- and I think life could be easier making them into a Single Table Inheritance called Contact_Event.
However, the way I have it set up now is when something is created for a Contact_Email, I have a dedicated controller that I call and know that I am passing the arguments that are approrpriate. For example, new_contact_email(contact, email).
I then have:
Emails.find(email.contact_id), etcera, all very specific to that Model.
I'm not sure how I extract the class/models to use.
For example, I currently have the following because I have separate controllers for each model:
  def do_event(contact, call_or_email_or_letter) 
    model_name = call_or_email_or_letter.class.name.tableize.singularize 
    link_to( "#{model_name.camelize}", send("new_contact_#{model_name}_path", 
                                            :contact => contact, 
                                            :status => 'done',
                                            :"#{model_name}" => call_or_email_or_letter ) )                                       
  end 
What I really want is to:
 link_to("#model_name.camelize}", send("new_contact_event_path(contact,call_or_email_or_letter)"
© Stack Overflow or respective owner