Penguin
Joined
Activity
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.
Hello,
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?
Thanks
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.
Hello,
With the payload:
{
"ref": "The penguin ref",
"object":{
"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}}?
Thanks