在Rails 3应用程序中,我有一个域类,其中一个属性存储纯HTML内容(它是一个博客应用程序,域类是Post).
在ERB模板中,我需要在格式化时显示属性的内容,并使用HTML标记.但是,Rails正在逃避所有HTML标签!如何为此类属性禁用此行为?
例:
somePost = Post.new
somePost.content = "<strong> Hi, i'm here! </strong>"
Run Code Online (Sandbox Code Playgroud)
在erb模板中:
<%= somePost.content %>
Run Code Online (Sandbox Code Playgroud)
生成的HTML被转义:
<strong> Hi, i'm here! </strong>
Run Code Online (Sandbox Code Playgroud)