2

I'm doing a sort of blog in Rails, and when I put something like

Hello, <b> how are you? </b>

inside the text_area and I send it, I see that it was saved as a plain text, and the HTML inside it is not recognized. The only thing I want is that every single HTML tag that I put in the text_area be interpreted as HTML and not as a plain text.

For example, the first code should be shown in my page like this:

Hello, how are you?

This is the code of the post's view new (in HAML):

= form_for @post do |f|
    .form
        .flabel= f.label :title
        = f.text_field :title
        .flabel= f.label :content
        = f.text_area :content
        .submit= f.submit "Create"

How could I do this without HTMLArea or things like that?

Thank you!!

2 Answers2

0

What about raw helper? Try the folliwing <%= raw @post.content %> in your view.

Sergey Kishenin
  • 5,099
  • 3
  • 30
  • 50
0

I think <%= @post.content.html_safe %> would also work.

larryzhao
  • 3,173
  • 2
  • 40
  • 62