URL encode & decode

I have a link:
<%= link_to ‘delete’, :action => ‘destroy’, :id => u(string_id) %>

Helper method ‘u()’ can encode a string to URL encoding, but I don’t
know which method can decode it? I want to used in controller. I have
not seen it in Rails’s document.

Thanks,

  • Li Jie

Li Jie wrote:

I have a link:
<%= link_to ‘delete’, :action => ‘destroy’, :id => u(string_id) %>

Helper method ‘u()’ can encode a string to URL encoding, but I don’t
know which method can decode it? I want to used in controller. I have
not seen it in Rails’s document.

---------------------------------------------------------- CGI::unescape
CGI::unescape(string)

  URL-decode a string.

    string = CGI::unescape("%27Stop%21%27+said+Fred")
       # => "'Stop!' said Fred"

(you will need

require ‘cgi’

in your controller)

regards

Justin

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