Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent Rails from encoding the ampersands in a URL when outputting JSON

I have the following code:

render json: { image: image }

Image has an attribute "url". Let's say it's:

https://blah.com/a?A=B&C=D

When rendering, this is what I get:

{"image":{"url":"https://blah.com/a?A=B\u0026C=D"}}

The ampersand is getting encoded as \u0026

Is there any way to avoid this encoding?

like image 216
Daniel Magliola Avatar asked Dec 09 '14 12:12

Daniel Magliola


1 Answers

Add to your application.rb file:

config.active_support.escape_html_entities_in_json = false
like image 142
olhor Avatar answered Nov 06 '22 21:11

olhor