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" %>
Was it helpful?

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.

OTHER TIPS

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" %>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top