How do I pass to link_to_remote a dynamic url in rails?
I am using link_to_remote and want to pass the following:
<%= link_to_remote "Skip Remote",
:url => url ,
:update => "update-area-#{contact.id}-#{next_todo.id}" %>
Where an example of url would be:
skip_contact_email_url(contact, email)
where contact is an object for model Contact and Email is an object for model Email.
But sometimes the url is skip_contact_letter_url, skip_contact_call_url, etcetera
Here's how I tried to do it, but it isn't working:
<% next_todo = contact.next_todo %>
<% url = "skip_contact_#{next_todo.class.name.tableize.singularize}_url" %>
<% url = url + "(#{contact}, #{next_todo})" %>
It correctly does the first part of the url (e.g. skip_contact_email_url) but does not pass the object. It actually looks like an object in the url.
What shou开发者_运维技巧ld I do?
You need evaluate your method generation.
<% next_todo = contact.next_todo %>
<% url = "skip_contact_#{next_todo.class.name.tableize.singularize}_url" %>
<% url = send(url, contact, next_todo) %>
精彩评论