How do I defined a variable link_to to an external URL

后端 未结 7 651
名媛妹妹
名媛妹妹 2020-12-09 07:58

On my site a user has a personal profile with a link to his personal external website. The url of the sites I store in a postgresql database under the name website

7条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-09 08:20

    I'm working with Rails 5 and I had the same problem. All I need to do to fix it, was to include the protocol on my link_to tag. E.g. I had www.google.com.mx, then, it should be http://www.google.com.mx. And that's it it works just fine like in the official doc is mentioned.

    So, finally I just have something like this in my view:

    <%= link_to (content_tag(:i, "help", class: 'material-icons tiny')), " http://www.google.com.mx", target: "_blank", rel: "alternate" %>
    

    Which is the same as:

    <%= link_to "help", "http://www.google.com.mx", target: "_blank", rel: "alternate" %>
    

    I hope it helps somebody else.

提交回复
热议问题