问题描述
@ post.body
具有以下内容(通过使用RDiscount从Markdown转换而来)。如何将它呈现给用户?即我想将它呈现为强文本 强调文字 ...
< p>< strong>强文本< / strong> < / p为H. < p>< em>强调文字< / em> < / p为H. < BLOCKQUOTE> < p>这是一个报价< / p> < / blockquote>< p>< img src =http://www.picturehouse.com/titles/images/rock.jpgalt =alt texttitle =/> < / p为H.
使用<%= @ post.body =>
将仅显示为上面显示的文本。 http://api.rubyonrails.org/classes/ActionView/Helpers/OutputSafetyHelper.html#method-i-rawrel =noreferrer> raw 辅助方法例如
<%= raw(@ post.body)%>
转义HTML输出在所有视图模板中默认打开(与之前的版本不同,您必须使用 h
方法分别转义字符串。)
@post.body
has following content (which is converted from Markdown by using RDiscount).How should I render it to the user in what it means? i.e I want to render it as strong text emphasized text...
<p><strong>strong text</strong> </p> <p><em>emphasized text</em> </p> <blockquote> <p>this is a quote</p> </blockquote><p><img src="http://www.picturehouse.com/titles/images/rock.jpg" alt="alt text" title="" /> </p>
Using <%= @post.body =>
will only display it as the text shown above.
Assuming Rails 3, use the raw helper method e.g.
<%= raw(@post.body) %>
Escaping HTML output is on by default in all view templates (in contrast to earlier versions where you had to use the h
method to escape strings individually.)
这篇关于如何使用原始html显示内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!