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]
Tweet