Passing array of parameters through get in rails

You should stick to using a GET request if you are not changing the state of anything, and all you want to to access a read only value.

To send an array of ids to rails in a GET request simply name your variable with square brackets at the end.

//angular snippet

  params: {'channel_id':2, 'product_ids[]': productIds}  
  //where productIds is an array of integers

Do not concatenate your ids as a comma separated list, just pass them individually redundantly. So in the url it would look something like this:


url encoded it will actually be more like this:


Rails will separate this back out for you.

Parameters: {"channel_id"=>"2", "product_ids"=>["6900", "6901"]}

Leave a Comment