{ id: "1",stuff: {"A" => [],"B" => [],"C" => [],"D" => []} }
如果数组中有任何值,则可以更改此值.但是说除了键“C”之外所有数组都有值,除了“C”之外它们都会在那里:
{ id: "1",stuff: {"A" => ["1"],"B" => ["2","3"],"D" => ["4"]} }
我正在从Rails 4.2.x升级到这个问题 – > 5.0.0
关于这里发生了什么的任何建议?我在munging parameters左右看过一些文章/问题,但是我不确定这是不是问题,因为在他们的示例表中,如何修改工作是{person:[]}变成{person:nil},其中人员param isn完全掉了下来.
解决方法
This is the expected behavior. There is no way to encode an empty
array using an HTML form (e.g. Content-Type: url-form-encoded). The
reason your tests passed in Rails 4.2 is because controller tests did
not encode their parameters,they simply passed the hash through
directly. In Rails 5 it encodes them. If your controller cares about
empty arrays,it’s likely that you are dealing with JSON requests. You
can do that in your test with as: :json. If you’re just dealing with
form input,you will never receive an empty array.
添加为:: json最终没有为我工作,但在测试开始时添加@ request.headers [“Content-Type”] =’application / json’.