Reputation: 335
In HTML, if I wanted a link to open in a new window, I'd adopt target="_blank" like this:
<a href="http://www.website.com/" target="_blank"><img src="/img.png" /></a>
How do I add the "_blank" to rails? Here's the code I so far for the link (but it currently opens in the same tab/window):
<%= link_to image_tag("img.png"), 'http://www.website.com/' %>
Upvotes: 21
Views: 27251
Reputation: 8678
For anyone wondering how to achieve this when passing a block:
<%= link_to(product.link, target: '_blank') do %>
Upvotes: 5
Reputation: 16730
I think it's like this
<%= link_to image_tag('img.png'), 'http://www.website.com', target: '_blank' %>
See http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to
Upvotes: 60
Reputation: 8202
you can remove the default action of the link in js as
$('#button-id').click(function(e){
e.preventDefault();
});
The preventDefault() function prevents the default action of the event
Upvotes: 0