link_to image tag. how to add class to a tag

前端 未结 11 1849
失恋的感觉
失恋的感觉 2020-12-22 20:53

I am using link_to img tag like following

<%= link_to image_tag(\"Search.png\", :border=>0, :class => \'dock-item\'), 
:action => \'search\', :co         


        
11条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-22 21:06

    Just adding that you can pass the link_to method a block:

    <%= link_to href: 'http://www.example.com/' do %>
        <%= image_tag 'happyface.png', width: 136, height: 67, alt: 'a face that is unnervingly happy'%>
    <% end %>
    

    results in:

    
        a face that is unnervingly happy
    
    

    This has been a life saver when the designer has given me complex links with fancy css3 roll-over effects.

提交回复
热议问题