I am trying to create single page inheritance.
However, the controller must know which class to look for or create. They are based on a different class.
For example, ContactEvent with type = Letter needs to capture attributes from the corresponding model named Letter.
Here is what I was trying to do and hit the miss marked below.
I need to be able to dynamically call the assignment of an EventClass value so that it can be Letter.find (: conditions =>) or Calls.find (: conditions =>) depending on what type of controller it is running on.
def new
@contact_event = ContactEvent.new
@contact_event.type = params[:event_type]
@contact_event.event_id = params[:event_id]
@contact_event.contact_id = params[:contact]
@EventClass = case
when @contact_event.type == 'letter' then 'Letter'
when @contact_event.type == 'call' then 'Call'
when @contact_event.type == 'email' then 'Email'
SNAG BELOW:
@event = @EventClass.find(@contact_letter.letter_id)
@event.body.gsub!("{FirstName}", @contact.first_name)
@event.body.gsub!("{Company}", @contact.company_name)
@evebt.body.gsub!("{Colleagues}", @colleagues.to_sentence)
@contact_event.body = @event.body
@contact_event.status = "sent"
end
source
share