# tinyMCE issues

**URL:** <https://www.ruby-forum.com/t/tinymce-issues/121588>\
**Category:** Rails\
**Created:** [November 29, 2007, 3:42am UTC](https://www.ruby-forum.com/t/tinymce-issues/121588 "2007-11-29T03:42:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![flamingsole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/f19dbf/32.png) [@flamingsole](https://www.ruby-forum.com/u/flamingsole)\
**Post date:** [November 29, 2007, 3:42am UTC](https://www.ruby-forum.com/t/tinymce-issues/121588/1 "2007-11-29T03:42:51Z")

</div>

Hello,

In using the tinyMCE plugin, I’m having issues with the html tags being  
entirely stripped out before being stored in the database.

Everything appears correctly in the textarea, with lists or bold or  
italics, or whatever, but when it is submitted nothing is preseved.

Now, my application\_helper.rb does have the following methods, but the  
tags are stripped even without these methods:

def remove\_tags(html, tags = [:a, :abbr, :acronym, :b, :blockquote,  
:cite, :code, :del, :em, :i, :q, :ul, :ol, :li, :p, :strike, :strong])  
sanitize(CGI::unescapeElement(CGI::escapeHTML(html), tags))  
end

def sanitize( html, okTags=‘a href, strong, br, em, p’ )

# no closing tag necessary for these

soloTags = [“br”,“hr”]

# Build hash of allowed tags with allowed attributes

tags = okTags.downcase().split(’,’).collect!{ |s| s.split(’ ') }  
allowed = Hash.new  
tags.each do |s|  
key = s.shift  
allowed[key] = s  
end

# Analyze all \<\> elements

stack = Array.new  
result = html.gsub( /(\<._?\>)/m ) do | element |  
if element =~ /\A\</(\w+)/ then  
#   
tag = $1.downcase  
if allowed.include?(tag) && stack.include?(tag) then  
# If allowed and on the stack  
# Then pop down the stack  
top = stack.pop  
out = “\</#{top}\>”  
until top == tag do  
top = stack.pop  
out \<\< “\</#{top}\>”  
end  
out  
end  
elsif element =~ /\A\<(\w+)\s_/\>/  
#   
tag = $1.downcase  
if allowed.include?(tag) then  
“\<#{tag} /\>”  
end  
elsif element =~ /\A\<(\w+)/ then  
# \<tag …\>  
tag = $1.downcase  
if allowed.include?(tag) then  
if ! soloTags.include?(tag) then  
stack.push(tag)  
end  
if allowed[tag].length == 0 then  
# no allowed attributes  
“\<#{tag}\>”  
else  
# allowed attributes?  
out = “\<#{tag}”  
while ( $’ =~ /(\w+)=("[^"]+")/ )  
attr = $1.downcase  
valu = $2  
if allowed[tag].include?(attr) then  
out \<\< " #{attr}=#{valu}"  
end  
end  
out \<\< “\>”  
end  
end  
end  
end

# eat up unmatched leading \>

while result.sub!(/\A([^\<]\*)\>/m) { $1 } do end

# eat up unmatched trailing \<

while result.sub!(/\<([^\>]\*)\Z/m) { $1 } do end

# clean up the stack

if stack.length \> 0 then  
result \<\< “\</#{stack.reverse.join(’\>\</’)}\>”  
end

result  
end

I thought remove\_tags specified tags that were allowed, but either way  
it seems like things should work when those methods are entirely  
removed. Any thoughts on how I can get this working? Thanks so much for  
any ideas.

Jonathan

---

<div class="post-metadata">

**Author:** ![flamingsole](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/f19dbf/32.png) [@flamingsole](https://www.ruby-forum.com/u/flamingsole)\
**Post date:** [November 29, 2007, 4:11am UTC](https://www.ruby-forum.com/t/tinymce-issues/121588/2 "2007-11-29T04:11:30Z")

</div>

Nevermind. I had a strip all tags function in a helper I hadn’t checked,  
and had forgotten about. Problem solved.
