Read more

How to generate a Rails-compatible query string

Dominik Schöler
January 27, 2016Software engineer at makandra GmbH

From Rails 3.0.9, there is a method Hash#to_query that will turn a Hash into a query string:

>> {:a => "a", :b => ["c", "d", "e"]}.to_query
=> "a=a&b%5B%5D=c&b%5B%5D=d&b%5B%5D=e"
>> CGI.unescape _
=> "a=a&b[]=c&b[]=d&b[]=e"
Illustration online protection

Rails professionals since 2007

Our laser focus on a single technology has made us a leader in this space. Need help?

  • We build a solid first version of your product
  • We train your development team
  • We rescue your project in trouble
Read more Show archive.org snapshot

If you're on the browser side, you can serialize nestd objects to query strings using jQuery's $.param Show archive.org snapshot .

Posted by Dominik Schöler to makandra dev (2016-01-27 11:42)