# Rails sanitize method is stripping my anchors

**URL:** <https://www.ruby-forum.com/t/rails-sanitize-method-is-stripping-my-anchors/158546>\
**Category:** Rails\
**Created:** [January 24, 2009, 5:22pm UTC](https://www.ruby-forum.com/t/rails-sanitize-method-is-stripping-my-anchors/158546 "2009-01-24T17:22:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![fipa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9e8a1a/32.png) [@fipa](https://www.ruby-forum.com/u/fipa)\
**Post date:** [January 24, 2009, 5:22pm UTC](https://www.ruby-forum.com/t/rails-sanitize-method-is-stripping-my-anchors/158546/1 "2009-01-24T17:22:58Z")

</div>

Hi,

I have some html pages that are saved in DB and which require anchors  
for quickly jumping inside the page. People can edit the page manually,  
so in order to keep things clean I use Rails sanitize method to clean  
the html before output. The problem is that it is stripping my anchors.

e.g:

## Our Team
 becomes 
## Our Team

How can I prevent sanitize from stripping the anchors? I have added "h2  
id’ to config.action\_view.sanitized\_allowed\_tags but it did not work.

---

<div class="post-metadata">

**Author:** ![fipa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9e8a1a/32.png) [@fipa](https://www.ruby-forum.com/u/fipa)\
**Post date:** [January 24, 2009, 6:03pm UTC](https://www.ruby-forum.com/t/rails-sanitize-method-is-stripping-my-anchors/158546/2 "2009-01-24T18:03:46Z")

</div>

Fernando P. wrote:

> Hi,
> 
> I have some html pages that are saved in DB and which require anchors  
> for quickly jumping inside the page. People can edit the page manually,  
> so in order to keep things clean I use Rails sanitize method to clean  
> the html before output. The problem is that it is stripping my anchors.
> 
> e.g:
> 
> ## Our Team
> becomes 
> ## Our Team
> 
> How can I prevent sanitize from stripping the anchors? I have added "h2  
> id’ to config.action\_view.sanitized\_allowed\_tags but it did not work.

By poking inside Rails’ source code, I have found that you can allow  
attributes with for instance:  
config.action\_view.sanitized\_allowed\_attributes = ‘id’

This way now, I can allow to mix html and markdown for creating such  
links.
