How to do url encoding for given text in rails?

hi,

for example, I have an string “q1 q2 q3”. how can I encode it in rails
to
produce the result like
“q1%20q2%20q3”.

Thanks!

Best Regards,
Zhenjian

CGI::escape(“your text”)

On 17/07/2006 08:32, Zhenjian YU wrote:

for example, I have an string “q1 q2 q3”. how can I encode it in rails
to produce the result like
“q1%20q2%20q3”.

If you just want to URL encode, you can use CGI.escape:

require ‘cgi’
puts CGI.escape “q1 q2 q3”

=> q1+q2+q3

Hope this helps,

Chris

hi,

for example, I have an string “q1 q2 q3”. how can I encode it in rails to
produce the result like
“q1%20q2%20q3”.

<%= u “q1 q2 q3” %>

Regards,
Rimantas

http://rimantas.com/

thank, all

it works

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs