920 Experience
1 Lesson Completed
1 Question Solved


Posted in

I ended up also disabling wrap_parameters: wrap_parameters format: []
So now I can simply do params.permit(:id, :name, :age).

Not sure if there is a better way.

Posted in


Note:I configured the App with config.action_controller.action_on_unpermitted_parameters = :raise.

Assuming I have a Model Person with attributes :name, :age.

If params = { name: "penguin", age: "99", style: "emperor" }

params.require(:person).permit(:name, :age) will not raise anything because params.require(:person) actually disregard the style: attribute without raising anything and returns { name: "penguin", age: "99" }

Now if I do params.permit(:id, :name, :age, :person => {}), it does raise "found unpermitted parameters: :style".

Is there a way to make .require not filtering the params without raising anything?


Yeah I know. I was hoping there would be a more "built-in" way to achieve that.
Thanks anyway!

Thanks for the quick answer!
The problem is that I pass params to a custom model that is going to set and validate each attribute. And the validation rejects the value of "object" as it expects something of type Hash but receives a type ActionController::Parameters.


With the payload:

"ref": "The penguin ref",
"a": 300,
"b": 30000,
"c": 10022

params.require(:stuff).permit(:ref, object: [:a, :b, :c]) returns:

{"ref"=>"The penguin ref", "object"=><ActionController::Parameters {"a"=>300, "b"=>30000, "c"=>10022} permitted: true>}

How to receive {"ref"=>"The penguin ref", "object"=> {"a"=>300, "b"=>30000, "c"=>10022}}?


logo Created with Sketch.

Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

© 2023 GoRails, LLC. All rights reserved.