How can I dynamically define the named route in a :partial in rails?

Posted by Angela on Stack Overflow See other posts from Stack Overflow or by Angela
Published on 2010-05-29T07:34:52Z Indexed on 2010/05/29 7:42 UTC
Read the original article Hit count: 157

Filed under:
|
|

I have the following partial. It can be called from three different times in a view as follows:

 <%= render :partial => "contact_event",
                    :collection => @contacts,
                    :locals => {:event => email} %>

Second time:

 <%= render :partial => "contact_event",
                    :collection => @contacts,
                    :locals => {:event => call} %>

Third time:

 <%= render :partial => "contact_event",
                    :collection => @contacts,
                    :locals => {:event => letter} %>

In each instance, call, email, letter refer to a specific instance of a Model Call, Email, or Letter.

Here is the content of the partial "contact_event":

            <%= link_to_remote "Skip #{event} Remote",
                              :url => skip_contact_email_url(contact_event, event),
                              :update => "update-area-#{contact_event.id}-#{event.id}" %>
            <span id='update-area-<%="#{contact_event.id}-#{event.id}"%>'> </span>
        </p>

My challenge: skip_contact_email_url only works when the event refers to an email.

  1. How can I dynamically define skip_contact_email_url to be skip_contact_letter_url if the local variable is letter?

  2. Even better, how can I have a single named route that would do the appropriate action?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about dynamic