url在rails中的ruby中等效编码 [英] url encode equivalent in ruby on rails

查看:95
本文介绍了url在rails中的ruby中等效编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Ruby on Rails 2.3.5中是否有等同于PHP的urlencode? (它编码要在URL的查询部分中使用的字符串) 我用谷歌搜索,但所有答案似乎都可以追溯到2006年之前,而且似乎还算是日期. 这就是我发现的东西.在视图中调用CGI::escape似乎有点异常.

Is there an equivalent to PHP's urlencode in Ruby on Rails 2.3.5? (It encodes a string to be used in a query part of a URL) I googled it but all the answers seem to date back to before 2006 and seems dates. This is what I found. It seems a bit abnormal to call CGI::escape in a view.

有等效的辅助功能吗?

谢谢!

推荐答案

我相信您正在寻找u辅助方法:

I believe the u helper method is what you're looking for:

<%=u "URL ENCODE <p>ME</p>" %>

我似乎找不到该方法的文档,但是如果我在不久的将来找到它,我将确保在此处添加一个链接.

I can't seem to find the documentation for that method, but if I find it in the near future I'll be sure to put a link in here.

您可以在此处.

这篇关于url在rails中的ruby中等效编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆