我在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" %>
我该怎么做才能在链接中和图像后面放置一些文字(如YouTube中的类似按钮)?
答案 0 :(得分:16)
您可以将块传递给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 %>
答案 1 :(得分:2)
将照片传递到here所述的块中。
答案 2 :(得分:2)
以防万一这里有人使用Slim作为视图引擎,在Rails 4中你可以这样做:
= link_to root_path
= image_tag 'logo.png'
答案 3 :(得分:1)
<% 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" %>