Friday, July 15, 2011

link_to with image_tag

How do you use Rails' link_to helper with the image_tag helper in your views?

Easy:
<%= link_to (image_tag "my_logo.png", :size => "150x50"), '/' %>

Just surround the image_tag part with parentheses and place it where you'd typically put the text to display in your link_to.

No comments:

Post a Comment

Please be considerate in what you say.