0

I pass a params like this

{
  "utf8" => true,
  "supply" => {
    "items" => { 111 => 112, 89 => 10},
    "another_params" => "something"
  }
}

My supply_params are:

params.fetch(:supply, {}).permit(:another_params, items: {})

But I get an unpermitted parameters 111 and 89. How can I make items permit all kinds of keys?

Alex Antonov
  • 14,134
  • 7
  • 65
  • 142

2 Answers2

1

This thread in github provides a solution:

def supply_params
  params.require(:supply).permit(:another_params).tap do |whitelisted|
    whitelisted[:items] = params[:supply][:items] if params[:supply][:items]
  end
end

The idea is to explicitly permit any known attributes which are needed and then tack on nested attributes.

steve klein
  • 2,566
  • 1
  • 14
  • 27
  • Lol I had forgotten all about this and then saw the comments today from you and @nathandva so I wrote it up. As long as you've solved your problem, that is fine. In the future, I'll try to write something up earlier so you can accept it. – steve klein Jun 24 '15 at 19:05
  • And I forgot about that :) – Alex Antonov Jun 25 '15 at 03:42
0

According to the @steve klein link to github issue, this is considered as a good solution:

params.permit(:test).tap do |whitelisted|
  whitelisted[:more] = params[:more]
end
Alex Antonov
  • 14,134
  • 7
  • 65
  • 142