简体   繁体   English

在MySQL和Heroku上为Rails设置富文本支持

[英]Setting up rich text support for Rails on MySQL and Heroku

What does it take to store a body of formatted text that contains bold, bullet points, and different sizes in Rails? 如何在Rails中存储包含粗体,项目符号和不同大小的格式化文本体?

Firstly, does the text field type have the ability to hold this? 首先, text字段类型是否具有保存此功能的能力?

If so, is it true that all I need to do is edit using a rich text editor, and display using <pre> ? 如果是这样,我需要做的就是使用富文本编辑器编辑,并使用<pre>显示?

Yes, the text type is designed to store character strings. 是的, text类型用于存储字符串。

The usual approach is to use a Javascript rich text editor which generates HTML. 通常的方法是使用生成HTML的Javascript富文本编辑器。 You save the raw HTML straight to the database, and then sanitize it when you display it. 您将原始HTML直接保存到数据库,然后在显示它时对其进行清理。 This is to prevent people from entering Javascript and other nasties into the text area that would get executed when other visitors view their input. 这是为了防止人们将Javascript和其他恶意软件输入文本区域,当其他访问者查看其输入时,这些区域将被执行。

Rails 3 sanitizes your output by default, so all HTML will be escaped. Rails 3默认清理您的输出,因此所有 HTML都将被转义。 You will need to call either <%= @model.rich_text.html_safe %> to skip this sanitizing, or (much better!) call <%= sanitize(@model.rich_text, :tags => %w(bip)) %> , passing in an explicit list of allowed tags. 您需要调用<%= @model.rich_text.html_safe %>来跳过此<%= @model.rich_text.html_safe %> ,或者(更好!)调用<%= sanitize(@model.rich_text, :tags => %w(bip)) %> ,传入允许标签的明确列表。

I have no experience with Heroku but I can't imagine it will be any different. 我没有使用Heroku的经验,但我无法想象它会有什么不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM