Kintarō
Kintarō

Reputation: 3177

Ruby on Rails: How to chain strong parameter if some of the parameters are nested attributes?

Suppose I have the following parameters:

"struct"=> {"content" => nil}, "name" => "structA"

When I try to build a strong parameters filter around it:

params = ActionController::Parameters.new("struct"=> {"content" => nil}, "name" => "structA")
params.permit(:struct, :name)

It only accept name:

=> {"name"=>"structA"}

I read some of the post that for the nested attribute, I need to use "require":

params.require("struct").permit!

But how can I chain the nested and non-nested attribute as one filter?

Upvotes: 0

Views: 676

Answers (1)

usha
usha

Reputation: 29349

Try this

params.permit(:struct => [:content], :name)

Upvotes: 2

Related Questions