<li class="li_spacing"><%= button_to "Website", @restaurant.website, :target => '_blank', :class => "btn btn-primary" %></li>
Everything works except for :target => '_blank'
. Why does this not render the the link in a new page?
<li class="li_spacing"><%= button_to "Website", @restaurant.website, :target => '_blank', :class => "btn btn-primary" %></li>
Everything works except for :target => '_blank'
. Why does this not render the the link in a new page?
Change from button_to
to a link_to
:
<%= link_to "Website", @restaurant.website, target: "_blank" %>
button_to
is generated inside a form, if you still wish to use it:
button_to "Website", @restaurant.website, class: 'btn btn-primary', form: {target: '_blank'}
A common way to open a link in a new window was to add a target="_blank"
to the link tag.
But for security reasons this should not be done anymore. It is recommended to use rel=noreferrer
instead:
link_to 'title', url, rel: 'noreferrer'
Or as a button:
button_to 'title', url, form: { rel: 'noreferrer' }
If you are using button_to
helper then it is automatically wrapped in a form by rails. So what you can do is to pass the attribute target: '_blank'
as:
button_to "Website", @restaurant.website, class: 'btn btn-primary', form: {target: '_blank'}