on mysite I have the ability to add comments. Sometimes users enter comments will links (href. ...)
I would like to have those links to be clickable/linkable (a href) when the comment is displayed to users.
how with Rails 3 can I take a comment, and look for links and then wrap those links in an a href tag that opens in a new window?
Thanks
The simplest way is to use the auto_link
method built into rails.
Note: In Rails 3.1 auto_link has been moved into a separate gem.
idlefinger's suggestion of #auto_link is perfect. I know it's not the question you originally posed, but wanted to suggest: also check out #simple_format, which will nicely format your users' use of newlines into br and p tags.
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