I am using Ruby on Rails 3 and I would like to extract from a string the first URL or e-mail address and then use the resulting string (examples: “http://www.test.com“, “mailto:test@test.com“, …) as the href attribute value used in a HTML <a href="resulting_string_value">Test link name</a>.
How can I do that in the safest way?
P.S.: I know the RoR auto_link method, but that does not accomplish what I need.
Ok, you probably didn’t want a regular expression, but it works, and you might use it as a helper
The code for urls:
The code for emails:
Putting it all together: