问题
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.
来源:https://stackoverflow.com/questions/60930886/rails-5-get-request-nested-array-parameter-changes-unexpectedly