Today I Learned

A Hashrocket project

Pass Array of Values As Query String in Rails

Rails provides a simple interface to pass an array as a query string.

Lets say we have an array:

platforms_ids = [0, 1, 2]

We can pass that to our endpoint as follows:

GET /platforms?platform_ids[]=0&platform_ids[]=1&platform_ids[]=2

And in our controller action, we can access those platform_ids with:

params[:platform_ids] 
=> [0, 1, 2]
Looking for help? Hashrocket has been an industry leader in Ruby on Rails since 2008. Rails is a core skill for each developer at Hashrocket and we'd love to take a look at your project. Contact us and find out how we can help you.