[英]Use %20 instead of + while setting cookie in rails
In a application I am working on , I need to set a string in the cookie, but if space is encoded as + in the cookie, and the front end is displaying as it is, how to use %20 instead of + while setting cookie.在我正在处理的应用程序中,我需要在 cookie 中设置一个字符串,但是如果在 cookie 中将空格编码为 +,并且前端按原样显示,如何在设置 cookie 时使用 %20 而不是 + . I used response['set_cookie']="key=value", but I dont want to use this, It would be nice if i could achieve the same using cookies[:id] = value
我使用了 response['set_cookie']="key=value",但我不想使用它,如果我可以使用 cookies[:id] = value 实现同样的效果就好了
%20
is the escaping character for a white space - if you meant escaping the value for setting it to the cookie. %20
是空格的转义字符 - 如果您的意思是转义将其设置为 cookie 的值。
If you want to replace it for something else, you can use gsub
:如果你想用其他东西替换它,你可以使用
gsub
:
"lola+lanos".gsub("+", "%20")
# "lola%20lanos"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.