在erb模板中禁用HTML转义 [英] Disable HTML escaping in erb templates

查看:166
本文介绍了在erb模板中禁用HTML转义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Rails 3应用程序中,我有一个域类,其中一个属性存储纯HTML内容(它是一个博客应用程序,域类是Post)。

In a Rails 3 application I have a domain class where one attribute stores pure HTML content (it's a blog app, the domain class is Post).

在ERB模板中,我需要按照格式显示属性的内容,HTML标签就位。但是,Rails正在转义所有的HTML标签!如何禁用此类属性的此行为?

In the ERB templates, I need to display the content of the attribute as it was formmated, with the HTML tags in place. But, Rails is escaping all HTML tags! How can I disable this behaviour for this class attribute?

示例:

somePost = Post.new
somePost.content = "<strong> Hi, i'm here! </strong>"

在erb模板中:

<%= somePost.content %>

生成的HTML已转义:

The HTML generated is escaped:

&lt;strong&gt; Hi, i'm here! &lt;/strong&gt;


推荐答案

尝试使用 。内容)。或者, somePost.content.html_safe

这篇关于在erb模板中禁用HTML转义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆