2013-12-08 43 views
0

我不知道這是否是一個愚蠢的問題,但我搜索了,我在Ruby on Rails 4中找不到像這樣的方法。我需要一種方法,如rawurlencode PHP,但on Rails的4Rails 4中替代方法RawUrlEncode PHP方法

從PHP文件爲Ruby:

Returns a string in which all non-alphanumeric characters except -_.~ have 
been replaced with a percent (%) sign followed by two hex digits. 
This is the encoding described in » RFC 3986 for protecting literal characters 
from being interpreted as special URL delimiters, and for protecting URLs from 
being mangled by transmission media with character conversions (like some email 
systems). 

所以,有一個在Ruby on Rails的這樣的方法?

回答

1

URI :: escape方法如何?

URI::escape('google.com/?q=what an awesome day') 

上述方法轉義輸入字符串,用代碼替換所有不安全的字符。也就是說,它使用百分比編碼對輸入進行編碼。你可以閱讀更多關於編碼百分比:

http://en.wikipedia.org/wiki/Percent-encoding

+0

謝謝Yosep!你能給更多的細節給其他有相同問題的人嗎?只需添加一些細節,我會給你最好的答案。再一次,謝謝,解決了我的問題! – Paladini