# Hyperlinks in comments

**URL:** <https://www.ruby-forum.com/t/hyperlinks-in-comments/186768>\
**Category:** Rails\
**Created:** [February 25, 2008, 10:03pm UTC](https://www.ruby-forum.com/t/hyperlinks-in-comments/186768 "2008-02-25T22:03:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![paradise](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/8e7dd6/32.png) [@paradise](https://www.ruby-forum.com/u/paradise)\
**Post date:** [February 25, 2008, 10:03pm UTC](https://www.ruby-forum.com/t/hyperlinks-in-comments/186768/1 "2008-02-25T22:03:19Z")

</div>

I am building a social networking site which currently has comments  
enabled. I was wondering if anyone knew how to enable html within  
these comments so that people can post links to other sites on the  
internet and have these links actually work if you click on them.  
Actually, this hyperlink capability is the only think that I really  
need. Anyone know how to enable hyperlinks in comments? Thanks, Dave

---

<div class="post-metadata">

**Author:** ![paradise](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/8e7dd6/32.png) [@paradise](https://www.ruby-forum.com/u/paradise)\
**Post date:** [February 25, 2008, 10:34pm UTC](https://www.ruby-forum.com/t/hyperlinks-in-comments/186768/2 "2008-02-25T22:34:41Z")

</div>

On Feb 25, 9:02 pm, Dave L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I am building a social networking site which currently has comments  
> enabled. I was wondering if anyone knew how to enable html within  
> these comments so that people can post links to other sites on the  
> internet and have these links actually work if you click on them.  
> Actually, this hyperlink capability is the only think that I really  
> need. Anyone know how to enable hyperlinks in comments? Thanks, Dave

Hi Dave,

I would suggest trying the sanitize helper. This can be configured to  
only permit certain HTML tags. The API docs are quite detailed.

> **[ActionView::Helpers::SanitizeHelper](https://api.rubyonrails.org/classes/ActionView/Helpers/SanitizeHelper.html)**
>
> The SanitizeHelper module provides a set of methods for scrubbing text of undesired HTML elements. These helper methods extend Action View making them callable within your template files.

Allow people to put anything in the comment (within reason of course -  
some input validation would be useful), and then use the helper in the  
view. The alternative of course is to use regular expressions to  
validate the input.

Best Regards

Robin

---

<div class="post-metadata">

**Author:** ![paradise](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/8e7dd6/32.png) [@paradise](https://www.ruby-forum.com/u/paradise)\
**Post date:** [February 25, 2008, 10:39pm UTC](https://www.ruby-forum.com/t/hyperlinks-in-comments/186768/3 "2008-02-25T22:39:20Z")

</div>

[http://www.railslodge.com/plugins/106-nofollow-links](http://www.railslodge.com/plugins/106-nofollow-links) may also come in  
useful if you go with the above approach.

else there is also an auto\_link text helper

> **[ActionView::Helpers::TextHelper](https://api.rubyonrails.org/classes/ActionView/Helpers/TextHelper.html#M001058)**
>
> The TextHelper module provides a set of methods for filtering, formatting and transforming strings, which can reduce the amount of inline Ruby code in your views.

Dave L. wrote:

> I am building a social networking site which currently has comments  
> enabled. I was wondering if anyone knew how to enable html within  
> these comments so that people can post links to other sites on the  
> internet and have these links actually work if you click on them.  
> Actually, this hyperlink capability is the only think that I really  
> need. Anyone know how to enable hyperlinks in comments? Thanks, Dave

---

<div class="post-metadata">

**Author:** ![paradise](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/8e7dd6/32.png) [@paradise](https://www.ruby-forum.com/u/paradise)\
**Post date:** [February 26, 2008, 2:17am UTC](https://www.ruby-forum.com/t/hyperlinks-in-comments/186768/4 "2008-02-26T02:17:21Z")

</div>

Hi Dave,

I assume you are asking this question because you already have  
something implemented and are wondering why links aren’t working. Have  
a look in your view code and remove the html escape method (“h”):-

\<%=h “some html text” %\>

and change the erb to:-

\<% “some html text” %\>

Once you have done that and the links are working I strongly suggest  
you look at SanitizeHelper as Robin suggested, you don’t want anyone  
to slip malicious code into your comments 😉

Jabbslad

---

<div class="post-metadata">

**Author:** ![paradise](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/8e7dd6/32.png) [@paradise](https://www.ruby-forum.com/u/paradise)\
**Post date:** [February 26, 2008, 11:13am UTC](https://www.ruby-forum.com/t/hyperlinks-in-comments/186768/5 "2008-02-26T11:13:35Z")

</div>

Awesome, this all looks like good advice. Thanks.

---

<div class="post-metadata">

**Author:** ![paradise](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/8e7dd6/32.png) [@paradise](https://www.ruby-forum.com/u/paradise)\
**Post date:** [February 26, 2008, 4:14am UTC](https://www.ruby-forum.com/t/hyperlinks-in-comments/186768/6 "2008-02-26T04:14:34Z")

</div>

I would suggest the whitelist plugin. That way you can set what they  
can and can’t do as far as html, like bold, italic, links, etc.
