Search code examples
ruby-on-railsactiveresource

How can url encoding be managed with ActiveResource?


Is there a way to manage URL encoding with ActiveResource? Specifically I am looking for a way to pass an email address as a parameter.

Currently my query fails as the @ symbol gets URL encoded to %40, causing the lookup on the remote app to fail.

For example, the following query on the ActiveResource model Person

Person.all(:from => :remote_find_by_email, :params => {:email => "john@example.com")

Produces the following URL

http://example.com/people/remote_find_by_email.xml?email=john%40example.com

Alternately, is there something the remote app should be doing to decode the parameter before performing the lookup?

UPDATE

Thanks to eks, I added the following method and before filter to the controller on the remote app:

before_filter :cgi_unescape_params, :only => [:remote_find_by_email]

private

  def cgi_unescape_params
    params.each { |k, v| params[k] = CGI.unescape(v) }
  end

Solution

  • Try using CGI::unescape on the remote end, that should take care of any % encoded value. Cheers!