-1

I currently need to send static content using API's created from admin using CKeditor.

Now when rendering the html contents in tags are not appering even after using raw and html_safe, escape_html etc

render json: {responseCode: xxx, responseMessage: "xxxxx." content: (@privacy_policy.try(:content)).html_safe}}

Output Currently appearing:

 "\u003cp\u003eLorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sodales augue nec dolor tincidunt, porttitor feugiat augue ultricies. Fusce eget hendrerit ante, non tristique sem. Suspendisse lacus justo, bibendum et suscipit nec, sagittis vel leo. Suspendisse et felis non est laoreet venenatis. Sed et aliquet dui. Fusce sit amet sapien ipsum. Proin est erat, egestas at rutrum sed, posuere at libero. Cras pretium risus sapien, non imperdiet elit ullamcorper a. Etiam ut leo eget erat eleifend posuere ut eu leo. Sed et aliquet dui. Fusce sit amet sapien ipsum. Proin est erat, egestas at rutrum sed, posuere at libero. Cras pretium risus sapien, non imperdiet elit ullamcorper a. Etiam ut leo eget erat eleifend posuere ut eu leo .\u003c/p\u003e\r\n"

Expected Output:

"<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sodales augue nec dolor tincidunt, porttitor feugiat augue ultricies. Fusce eget hendrerit ante, non tristique sem. Suspendisse lacus justo, bibendum et suscipit nec, sagittis vel leo. Suspendisse et felis non est laoreet venenatis. Sed et aliquet dui. Fusce sit amet sapien ipsum. Proin est erat, egestas at rutrum sed, posuere at libero. Cras pretium risus sapien, non imperdiet elit ullamcorper a. Etiam ut leo eget erat eleifend posuere ut eu leo. Sed et aliquet dui. Fusce sit amet sapien ipsum. Proin est erat, egestas at rutrum sed, posuere at libero. Cras pretium risus sapien, non imperdiet elit ullamcorper a. Etiam ut leo eget erat eleifend posuere ut eu leo .</p>\r\n"

Note: When checking on Postman the data is appearing in correct format but when checking on RestClient or using curl request the problem is appearing. Rails Version = 5.2

Rohan
  • 2,681
  • 1
  • 12
  • 18
  • html_safe working fine here, it did what it supposed to do, "\u003c" is the unicode version of '<', what is the original string ? (without html_safe) – D1ceWard Jun 12 '18 at 11:35
  • Expected Output is the original string saved in database and this is what I want when rendering with json format – Rohan Jun 12 '18 at 18:03
  • so just remove html_safe method, html_safe marks a string as trusted safe to be executed as html – D1ceWard Jun 13 '18 at 07:54
  • Adding this worked: ActiveSupport::JSON::Encoding.escape_html_entities_in_json = false – Rohan Jun 13 '18 at 07:59

1 Answers1

0

So, finally got it working using this in current environment file:

ActiveSupport::JSON::Encoding.escape_html_entities_in_json = false

As after 4.2.6 releases it defaults to true

Rohan
  • 2,681
  • 1
  • 12
  • 18