Andrew Backes
Andrew Backes

Reputation: 1904

Ruby on Rails - Escape HTML Entities in JSON

I recently upgraded an old rails app from version 4 to 6, and have noticed that my json views (view jbuilder) are now escaping any HTML entity. For example, amersands are now appearing as \u0026. Previously, I was able to avoid this by setting config.active_support.escape_html_entities_in_json = false in my application.rb. This doesn't seem to do anything anymore...what's the rails 6 way to configure this?

Upvotes: 3

Views: 1140

Answers (1)

Andrew Backes
Andrew Backes

Reputation: 1904

I was able to get this working in Rails 6 by creating an initializer with the following contents:

ActiveSupport.escape_html_entities_in_json = false

No idea why the old way isn't working, especially as the documentation still says it is a valid configuration option (as of 2/27/2021).

Upvotes: 3

Related Questions