Alex
Alex

Reputation: 4517

What should I store the content of text_area in a forms in Rails?

Additionally if I want to store HTML in that text_area how can I render it as HTML?

Thanks,

Alex

Upvotes: 0

Views: 134

Answers (1)

Pierre-Luc Simard
Pierre-Luc Simard

Reputation: 2721

Not entirely sure what you are asking for. But the basics are:

Your text area should most likely be linked to a an attribute of type TEXT so you are not limited in the size. See the migration guide for details.

As for storing straight HTML, it's dangerous to let user input arbitrary HTML content, specially if it's going to be seen by other user (for example on a forum) as it would allow anybody to add javascript to the page. This is also known as XSS or Cross site scripting. Think of at least of sanitizing the input.

To display the "raw" HTML content, in Rails 3 you need to add .html_safe to your attribute. This mean Rails will not clean it up and will render the content as is in the page.

Upvotes: 1

Related Questions