Rails 3 does not render HTML as markup

I submitted a form to create a single row in an SQL database table as a blog entry:

<p>This is a paragraph.</p>

And the result, when I request it for display, through Rails ActiveRecord, it looks like this:

<p>This is a paragraph.</p>

and here is the code when I view the source code in a browser:

&lt;p&gt;This is a paragraph.&lt;/p&gt;

How can i solve this? Or do I just need to convert < and > using Javascript?

Thank:)

+3
source share
1 answer

What happens is that the string is HTML escaped.

You can use html_safeit so as not to leave the line when rendering it. Eg <%= post.paragraph.html_safe %>.

, , , ( ) HTML, , , , JavaScript (, XSS). , .

. , HTML HTML html_safe HTML. , ( , " " !).

, StackOverflow.

+7

Source: https://habr.com/ru/post/1784806/


All Articles