在输出JSON时,阻止Rails编码URL中的&符号 [英] Prevent Rails from encoding the ampersands in a URL when outputting JSON
本文介绍了在输出JSON时,阻止Rails编码URL中的&符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码:
render json: { image: image }
图片有一个属性url。假设是:
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?
推荐答案
添加到您的 application.rb 文件:
config.active_support.escape_html_entities_in_json = false
这篇关于在输出JSON时,阻止Rails编码URL中的&符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文