1

我保存了一个带有 html 标签的字符串。

=> "<p>hey man this is crazy g funk</p>\n<p>here i come with another crazy message from..</p>\n<p>dj eassssy d!@#!.</p>"

您如何解析它以显示 HTML 标记所暗示的方式?

我试过:

= Post.text
=h Post.text
= RedCloth.new(Post.text).to_html
= Hpricot(Post.text)
4

2 回答 2

4

你想这样做:

<%= raw Post.text %>

或在火腿

= raw Post.text

原因是因为 rails 会转义您的 html 并转换<p>&lt;p&gt;.

于 2010-11-30T19:52:34.137 回答
1

通常使用 html 解析器解析 html。您是什么意思“以便它显示 HTML 标记所暗示的方式”?在什么上显示?应该不是浏览器吧。。

于 2010-11-30T19:40:26.807 回答