Rails: Open link in new tab (with ‘link_to’)

Rails: Open link in new tab (with ‘link_to’)

Asked on January 11, 2019 in Ruby on Rails.
Add Comment


  • 2 Answer(s)

       The target: :_blank parameter should be a parameter of link_to, image_tag parameters

    <%= 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 %>
    

    Answered on January 11, 2019.
    Add Comment

    Follow this below command: 

    <%= link_to image_tag("facebook.png", :class => "facebook_icon", :alt => "Facebook"), "http://www.facebook.com/mypage", :target => "_blank" %>
    

    Answered on January 11, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.