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

Using a number as a nested key breaks permit #239

@anthonator

Description

@anthonator

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions