link_to external site, without "http://" in url

Hi

I have a form where users enters their homepage-url. The problem is that some users don't include the "http://" part of the url.

So, when I use <%= link_to "external site", @user.homepage_url %> and @user.homepage_url is "www.homepage.com", Rails maps this to a internal site (which, of course, doesn't exists).

Is there a easy way to fix this, or do i need a method that checks for, and includes, the "http://" part of a url?

Hi,

Is there a easy way to fix this, or do i need a method that checks for, and includes, the "http://" part of a url?

You should always store the http:// with the link. Try to validate your model width szh like this:

web = "www.domain.de"

puts (web[0..7] != "http://") ? "http://#{web}" : web

HTH, Beate

unless, of course, you want to allow https:// , or even mailto: , etc...