Skip to content
This repository has been archived by the owner on Aug 17, 2017. It is now read-only.

Using a number as a nested key breaks permit #239

Open
anthonator opened this issue Mar 28, 2016 · 0 comments
Open

Using a number as a nested key breaks permit #239

anthonator opened this issue Mar 28, 2016 · 0 comments

Comments

@anthonator
Copy link

I ran into an issue today with nested numbers as keys breaking permit. It only breaks if the key is nested. If it's a top-level key it works just fine.

I'm using Rails 4.2.6 and Ruby 2.3.0.

Examples:

broken

params = ActionController::Parameters.new(photos: { '1' => { 'hello': 'world' } })
params.permit(photos: { '1' => [:hello] }) # => {"photos"=>{"1"=>{}}}

works

params = ActionController::Parameters.new('1' => { 'hello': 'world' })
params.permit('1' => ['hello']) # => {"1" => { "hello": "world" }}
params = ActionController::Parameters.new(photos: { 'key_1' => { 'hello': 'world' } })
params.permit(photos: { 'key_1' => [:hello] }) # => {"photos"=>{"key_1"=>{"hello"=>"world"}}}

Of course renaming your keys is the easy workaround. Just thought I'd create some documentation around the issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant