Linking an Image to an External URL

I am trying to associate an image with an external url from my index.html.erb page, but it does not work. Any suggestions?

<%= link_to image_tag "facebook.png",  "http://www.facebook.com"  %>

I am also trying to link the “send to friend” email image, so when a user clicks on it, their email client will automatically open with a pre-written header and message ready to be sent. Can anyone help with this?

+5
source share
1 answer

You might think that url is the second parameter to the method image_tag, not the method link_to, so wrap this in parameters image_tagin parentheses to avoid confusion:

<%= link_to image_tag("facebook.png"), "http://www.facebook.com" %>
+6
source

All Articles