gpt4 book ai didi

ruby-on-rails - rails : "currency" is escaped/transformed to "¤cy" without my asking

转载 作者:数据小太阳 更新时间:2023-10-29 07:56:21 24 4
gpt4 key购买 nike

我在我的 Rails 3.2.9 应用程序中遇到了一件非常奇怪的事情 - 当我渲染它时:

render inline: BusinessesController.checkout_page_url(...)

用这个方法:

def self.checkout_page_url(business, order_number)
url = ''
# ...
url << 'currency=' << conf['currency'] << '&'
# ...
puts url
return url
end

然后生成的 url 在控制台中呈现得很好(puts url):

... currency=EUR& ...

但浏览器中呈现的字符串显示为:

... ¤cy=EUR& ...

我试过在渲染字符串之前调用 .html_safe,但没有改变任何东西。当将 currency 更改为 curency(有错字)时,一切正常。

这是怎么回事?

最佳答案

这是因为 ¤ 的 HTML 代码是 ¤。检查http://www.ascii.cl/htmlcodes.htm .

因此浏览器正在用符号替换它。

要绕过它,请尝试这样做:

<%= h url%>

在你看来。其中“h”是用于转义的旧 Rails 助手。

关于ruby-on-rails - rails : "currency" is escaped/transformed to "¤cy" without my asking,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18594105/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com