Ruby URL to convert html links

I am creating a simple chat application with Rails. when the user enters the url, I want it to be displayed as an html link (ie "url").

I was wondering if there is any library or known way to do this in Ruby. If not, I have some nice regex example code to work with ...

+5
source share
1 answer

Check out the auto_link helper method provided by Rails. This turns all urls and email addresses into interactive links (html anchor tags). Here is a sample code from the docs.

auto_link("Go to http://www.rubyonrails.org and say hello to david@loudthinking.com")
# => "Go to <a href=\"http://www.rubyonrails.org\">http://www.rubyonrails.org</a> and
#     say hello to <a href=\"mailto:david@loudthinking.com\">david@loudthinking.com</a>"
+9
source

All Articles