Skip to content

Instantly share code, notes, and snippets.

@jmccartie
Last active December 10, 2015 20:38
Show Gist options
  • Save jmccartie/4489565 to your computer and use it in GitHub Desktop.
Save jmccartie/4489565 to your computer and use it in GitHub Desktop.
Rails 3.2.11 --> Empty arrays being parsed as "nil" instead of empty array

Rails 3.2.10

Post JSON with nested attributes:

> RestClient.post "http://localhost:3000/users.json", {"users" => [] }.to_json, { 'Content-Type' => 'application/json'}

Dump params from controller:

{"users"=>[], "action"=>"create", "controller"=>"users", "format"=>"json"}

Note that "addresses" is an empty array

Rails 3.2.11

Post JSON with nested attributes:

> RestClient.post "http://localhost:3000/users.json", {"users" => [] }.to_json, { 'Content-Type' => 'application/json'}

Dump params from controller:

{"users"=>{}, "action"=>"create", "controller"=>"users", "format"=>"json"})

Note that "user" is no longer an empty array.

We've noticed that the change also affects nested attributes (the parsed value will be nil)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment