[Ruby] [Rails] I want to display link_to link destination in another tab

less than 1 minute read

I want to display it in another tab when using link_to with Rails, so I made a note because it was implemented.

Procedure

First, specify the character string you want to display with link_to and the link destination URL.

<%= link_to "string", "link destination URL" %>

Add target: :_blank to display in another tab

<%= link_to "string", "link URL", target: :_blank %>

Now you can open it in another tab. However, this has problems in terms of performance and security. .. ..

It seems to be good to add rel="noopener noreferrer" to avoid this problem.

<%= link_to "character string", "link destination URL", target: :_blank, rel: "noopener noreferrer" %>

Now you can open another tab with confidence.

Tags: ,

Updated: