2013-05-04 64 views
1

我需要这个图像链接到profile_path(thing.user)使用的link_to使图像的链接

<%= image_tag thing.user.photo.url(:small), { :class=>"rounded_square" , 
    style: "margin-left:8px; text-align:center; vertical-align:middle;" } %> 

回答

4

link_to应该采取一个块,如果没有什么帮助:

<%= link_to profile_path(thing.user) do %> 
    <%= image_tag thing.user.photo.url(:small), { :class=>"rounded_square" , 
style: "margin-left:8px; text-align:center; vertical-align:middle;" } %> 
<% end %> 
+0

杜,谢谢你! – 2013-05-04 18:49:07

1
= link_to somewhere_path(some_object) do 
    = image_tag some_object.url, class: 'rounded_square' 
end 

块的返回值将成为a标签的内容。

0

你可以使用嵌套ERB尝试。

<%= link_to "#{image_tag(yourimagepath)}", "link_path" %> 

应该看起来像这样。

 <%= link_to "#{image_tag thing.user.photo.url(:small), 
     { :class=>'rounded_square' , style: "margin-left:8px; text-align:center; vertical-align:middle;" }}", 
     "profile_path(thing.user)" %> 
相关问题