Question

I'm trying to embed additional code in a link_to but not sure how to get it to work. How do I go about doing that? I'm trying to get this to work:

<%= link_to image_tag("Favorite 3.png", class: "act_actions", title: "Unfavorite", alt: "Unfavorite") + <%= activity.votes.size %>, favorite_activity_path(activity), method: :put, :remote => true, :class => "btn favorite" %>
Était-ce utile?

La solution

I would try to use linkt_to as block to gain readability

<%= link_to favorite_activity_path(activity), method: :put, :remote => true, :class => "btn favorite" do %>
  <%= image_tag("Favorite 3.png", class: "act_actions", title: "Unfavorite", alt: "Unfavorite") %>
  <%= activity.votes.size %>,
<% end %>

I hope that the above code works for you.

Autres conseils

you can do it this way also.

<%= link_to "#{image_tag('Favorite 3.png', class: 'act_actions', title: 'Unfavorite', alt: 'Unfavorite')} #{activity.votes.size}".html_safe, favorite_activity_path(activity), method: :put, :remote => true, :class => "btn favorite" %>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top