Reputation: 56729
What does it take to store a body of formatted text that contains bold, bullet points, and different sizes in Rails?
Firstly, does the text
field type have the ability to hold this?
If so, is it true that all I need to do is edit using a rich text editor, and display using <pre>
?
Upvotes: 4
Views: 1673
Reputation: 20687
Yes, the text
type is designed to store character strings.
The usual approach is to use a Javascript rich text editor which generates HTML. You save the raw HTML straight to the database, and then sanitize it when you display it. 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.
Rails 3 sanitizes your output by default, so all HTML will be escaped. 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(b i p)) %>
, passing in an explicit list of allowed tags.
I have no experience with Heroku but I can't imagine it will be any different.
Upvotes: 6