当前位置: 动力学知识库 > 问答 > 编程问答 >

Placing an image and text inside an link_to helper (Rails)?

问题描述:

I added an image inside a link_to helper:

 <% 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 it so that I can place some text within the link and right after the image (like the like button in YouTube)?

网友答案:

You can pass a block to the link_to helper

<%= 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 %>
网友答案:

Pass the pic in a block as mentioned here.

网友答案:

Just in case anyone here is using Slim as the view engine, in Rails 4 you can do:

= link_to root_path
  = image_tag 'logo.png'
网友答案:
<% 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" %>
分享给朋友:
您可能感兴趣的文章:
随机阅读: