RAILS link_to external site, url is attribute of user table, like: @users.website RAILS link_to external site, url is attribute of user table, like: @users.website ruby-on-rails ruby-on-rails

RAILS link_to external site, url is attribute of user table, like: @users.website


You can prepend url with protocol if it's absent:

module UrlHelper  def url_with_protocol(url)    /^http/i.match(url) ? url : "http://#{url}"  endend

And then:

link_to @user.site, url_with_protocol(@user.url), :target => '_blank'


Looks like you need to stick the protocol on your link. E.g. you have www.userswebsite.com in your database, it should be http://www.userswebsite.com


You are storing URLs without the http:// so they are being interpreted as relative URLs.Try this:link_to @user.site, "http://#{@user.url}"