"like", :cl...">

Placing image and text inside link_to (Rails) helper?

I added an image inside the link_to :

  <% like = image_tag("like.png", :alt => "like", :class => "like") %> <%= link_to like, vote_up_path(@votable, :votable_type => "Post"), :remote => true, :class => "vote-up default button" %> 

How can I do this to place text inside the link and right after the image (for example, on YouTube)?

+6
source share
4 answers

You can pass the block to the link_to

 <%= link_to vote_up_path(@votable, :votable_type => "Post"), :remote => true, :class => "vote-up default button" do %> <%= image_tag("like.png", :alt => "like", :class => "like") %> <span>Like</span> <% end %> 
+14
source

Pass the pic. in the block as indicated here .

+2
source

Just in case, if someone uses Slim as a viewer, in Rails 4 you can do:

 = link_to root_path = image_tag 'logo.png' 
+2
source
 <% like = image_tag("like.png", :alt => "like", :class => "like") %> <%= link_to "#{like} your text", vote_up_path(@votable, :votable_type => "Post"), :remote => true, :class => "vote-up default button" %> 
+1
source

Source: https://habr.com/ru/post/910171/


All Articles