0

I have upgraded a Rails 4 application to Rails 5 (5.2.4.1 to be exact).

I have a GET endpoint in my code with an rspec test.

The test code sends the request as:

get :fetch, params: { id: 123, logs: [[1, 2, :weekly], [1, 4, :mothly]] }

When the controller receives the request, params['logs'] contains

[["1"], ["2"], ["weekly"], ["1"], ["4"], ["monthly"]]

This is different from what I expected, which is

[["1", "2", "weekly"], ["1", "4", "monthly"]]

The incoming URL contains (after decoding the URL): ?id=123&logs[][]=1&logs[][]=2&logs[][]=weekly&logs[][]=1&logs[][]=4&logs[][]=monthly

This is the same URL in Rails 4, but it worked somehow. Was something else being passed? In any case, it's no longer working Rails 5. The Rails doc https://edgeguides.rubyonrails.org/action_controller_overview.html#hash-and-array-parameters does not mention nested array parameters.

Is it possible to make this work with Rails 5? Is there any quick workaround?

The problem could be with rack gem. The two versions used are: 1.6.13 and 2.2.2.

(I can send the whole structure as a json string in one parameter; I know this is an alternative solution. So please don't propose this as a solution.)

Thank you.

Zack Xu
  • 11,505
  • 9
  • 70
  • 78
  • For this kind of params, I usually use `post`. I know that `post` is only for `posting` or `creating` data, but it can handle a bigger request param because your `logs` can get bigger with time. – Roc Khalil Mar 30 '20 at 13:39
  • Try this: https://stackoverflow.com/a/23066966/9273735 – Mrunal Selokar Apr 02 '20 at 06:18

0 Answers0