Foo 如何在字符串中执行此操作?我想做这样的事情: ">Foo 这一定是微不足道的,对吧? 最佳答案-6ren">
gpt4 book ai didi

ruby-on-rails - 如何在 Rails 中对字符串进行 URL 转义?

转载 作者:行者123 更新时间:2023-12-03 05:52:35 27 4
gpt4 key购买 nike

如果我在 Rails 中的 RHTML View 中,很容易对某些内容进行 URL 转义:

<a href="/redirect?href=<%=u target %>">Foo</a>

如何在字符串中执行此操作?我想做这样的事情:

<% redirect_href = "/redirect?#{url_escape target}&amp;foo=bar&amp;baz=some_other_stuff" -%>
<a href="<%= redirect_href =>">Foo</a>

这一定是微不足道的,对吧?

最佳答案

CGI.escape会做的:

<% redirect_href = "/redirect?#{CGI.escape target}&amp;foo=bar&amp;baz=some_other_stuff" -%>
<a href="<%= redirect_href =>">Foo</a>

关于ruby-on-rails - 如何在 Rails 中对字符串进行 URL 转义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6057972/

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