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...
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>"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With