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 book lover

Growing Rails Applications in Practice

Check out our e-book. Learn to structure large Ruby on Rails codebases with the tools you already know and love.

  • Introduce design conventions for controllers and user-facing models
  • Create a system for growth
  • Build applications to last
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)