The target: :_blank
parameter should be a parameter of link_to
, whereas you put it in image_tag
parameters. Modify your code like this:
<%= link_to image_tag("facebook.png", class: :facebook_icon, alt: "Facebook"), "http://www.facebook.com/mypage", target: :_blank %>
Or with a block:
<%= link_to "http://www.facebook.com/mypage", target: :_blank do %>
<%= image_tag("facebook.png", class: :facebook_icon, alt: "Facebook") %>
<% end %>
Try this:
<%= link_to image_tag("facebook.png", :class => "facebook_icon", :alt => "Facebook"), "http://www.facebook.com/mypage", :target => "_blank" %>
You can also use target: :_blank
instead of target: '_blank'
<%= link_to image_tag("facebook.png", class: "facebook_icon", alt: "Facebook"), "http://www.facebook.com/mypage", target: :_blank %>
link_to do
<%= link_to "http://www.facebook.com/mypage", target: :_blank do %>
<%= image_tag "facebook.png", class: "facebook_icon", alt: "Facebook" %>
<% end %>
If you're looking for how to open a link in a new tab within html (for anyone came here from Google), here:
<a href="http://www.facebook.com/mypage" target="_blank">Link name</a>
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