Tony
Tony

Reputation: 1011

Rails: How to add external link to rails app

I have a string in which users input a URL, which is later displayed in index.html. How can I turn that into a working external link? Right now, the link displays as should (e.g. www.facebook.com/tester), but when I click on the link I get a no route matches "/www.facebook.com/tester" routing error. I tried user.facebook.link but that didn't work.

I tried adding href=" " also but with no luck.

<%= link_to nil, user.facebook %>

Upvotes: 3

Views: 3827

Answers (1)

leenasn
leenasn

Reputation: 1486

As mentioned by @Mischa, you can add:

<%=link_to nil, "http://#{user.facebook}"%>

to have the protocol added to link.

If you need to give the link a label, say, Facebook, you can use it:

<%=link_to 'Facebook', "http://#{user.facebook}"%>`

That's all.

I hope this helps

Upvotes: 6

Related Questions