I'm trying to link an image to an external URL from my index.html.erb page but it's not working. Any suggestions?
<%= link_to image_tag "facebook.png", "http://www.facebook.com" %>
I am also trying to link a 'send-to-friend' email image - so when a user clicks it, their email client will open automatically with a pre-written title and message ready to send. Can anyone help with this one?
Complete HTML/CSS Course 2022 To use image as a link in HTML, use the <img> tag as well as the <a> tag with the href attribute. The <img> tag is for using an image in a web page and the <a> tag is for adding a link. Under the image tag src attribute, add the URL of the image.
To create a clickable image online, all you need is a JPG file and a website address (the URL). Just as you can add a link to any text on a web page or Word document, you can add a link to any image file, including JPGs, PNGs and GIFs.
It may be thinking the url is a second parameter to the image_tag
method rather than to the link_to
method, so wrap that up the image_tag
parameters in parentheses to avoid confusion:
<%= link_to image_tag("facebook.png"), "http://www.facebook.com" %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With