Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby url to html link conversion

I'm building a simple chat app with Rails. when a user types in a url, I want it to be output as an html link (ie, "url").

I was wondering if there is any library or well known way to do this in Ruby. If not, I've got some decent regex sample code to work with...

like image 591
user94154 Avatar asked Aug 08 '09 20:08

user94154


1 Answers

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

auto_link("Go to http://www.rubyonrails.org and say hello to [email protected]")
# => "Go to <a href=\"http://www.rubyonrails.org\">http://www.rubyonrails.org</a> and
#     say hello to <a href=\"mailto:[email protected]\">[email protected]</a>"
like image 91
ryanb Avatar answered Nov 12 '22 14:11

ryanb