Nested Parameters returns ActionController::Parameters rather than parameter value
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
It's the same. Strong params is just a Hash-like object so you don't have to do anything special to it. It's designed like that to work seamlessly but be secure.
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.
Yeah I know. I was hoping there would be a more "built-in" way to achieve that.
Thanks anyway!
Yep, that's the built-in way. Sounds like your code doing the validation is strict about what type of object it is (a Hash) and that's the part that's not very Ruby-ish.