Return unescaped html with jbuilder

I want to return html content via jbuilder:

json.array!(@articles) do |article| json.extract! article, :id, :title, :html_content end 

But it returns escaped html:

 { "id": 2, "title": "", "html_content": "\u003cp\u003e\u003cimg alt=\"\" src=\"#\" /\u003e\u003c/p\u003e\r\n" } 

How can it return unescaped html?

+5
source share
2 answers

You can use html_safe to disable the evacuation function. You probably ran into some problems because " also will not be escaped, and it is used to determine the value in JSON.

I think the best approach is to somehow encode it, for example, with base64 :

+1
source

I believe the answer is not to get the value through extract! I think this should do the trick.

 json.array!(@articles) do |article| json.extract! article, :id, :title json.html_content article.html_content end 
0
source

All Articles