How do I dynamically change the path_to()?

Posted by Angela on Stack Overflow See other posts from Stack Overflow or by Angela
Published on 2010-05-08T04:39:34Z Indexed on 2010/05/08 4:48 UTC
Read the original article Hit count: 166

Filed under:
|

I currently have three methods which I want to collapse into one:

  def send_email(contact,email)

  end

  def make_call(contact, call)
    return link_to "Call", new_contact_call_path(:contact => contact, :call => call, :status => 'called')
  end

  def make_letter(contact, letter)
    return link_to "Letter", new_contact_letter_path(:contact => contact, :letter => letter, :status => 'mailed')
  end

I want to collapse the three into one so that I can just pass the Model as one of the parameters and it will still correctly create the path_to. I am trying to do this with the following, but stuck:

  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}", new_contact_#{model_name}_path(contact, call_or_email_or_letter)" 
  end

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about send