1

I have an instance with a description:

instance = Object.new
instance.description = '<a href=www.google.com >Google</a>'

Then in the view, I display it using

= sanitize(instance.description)

It displays the link correct but when I hover over the link and I look at the url it will redirect to 'www.my-web-app.com/www.google.com' (it prepends the domain of my app to the correct url), anyone knows what's causing this? please help me.

Thanks in advance

Cecille Manalang
  • 213
  • 3
  • 14

2 Answers2

2

You should add http:// to the URL:

instance.description = '<a href=http://www.google.com >Google</a>'
Mischa
  • 42,876
  • 8
  • 99
  • 111
2

You href needs to have an http:// so,

instance.description = "<a href='http://google.com'>Google</a>"

The problem is with the HTML, it has nothing to do with rails.

iltempo
  • 15,718
  • 8
  • 61
  • 72
Rishav Rastogi
  • 15,484
  • 3
  • 42
  • 47