interpreting escaped html
I am using rails 3.0 and I have an xml file where I store the content of my webpage. So for example, to fill in the body section of a given html page, I extract the content of the tag using REXML methods in ruby.
I would like to store a content with HTML tag inside this XML tag. Say, the following is my favorite content:
<body><strong>XXX</strong></body>
I am inserting this text in its escaped version so that XML parser doesn't interpret it as some co开发者_运维问答ntent.
"<strong> XXX </strong>"
Running seeds.rb file, I am reading this content to the database and eventually render it as an html page.
I tried many methods, I was unable to obtain what I want, namely: XXX
thanks for your help.
Another easy to output raw content
<%== @content.body %>
It's exactly the same as
<%= raw @content.body %>
it's just a shorthand method to output raw content
try putting the html inside a CDATA
section (unescaped):
<xmlNode>
<![CDATA[
<body><strong>XXX</strong></body>
]]>
</xmlNode>
solved the problem, in my XML file, I have this content entered unescaped as it is:
<body>
<strong>XXX</strong>
</body>
in my seeds.rb file, I read the child of node with:
k.children[1].to_s
and finally in the controller, I declare the content as .html_safe
:
<%= content_tag(:div, @content.body.html_safe) %>
精彩评论