2

I wanna read an array of hashes as parameter from postman (or anything else).

postman:

{
  "domains": [
     {"id":"1", "name": "aa"},
     {"id":"2", "name": "bb"}
  ]

}

I need to read this parameter exactly like this:

ruby on rails:

 [
     {"id":"1", "name": "aa"},
     {"id":"2", "name": "bb"}
 ]

How can I do that?

2
  • What is context? Is the first codeblock the JSON body (with Content-Type: application/json) of a POST request? If so have you tried accessing it using params[:domains] in the controller? Commented Nov 2, 2020 at 10:16
  • yes, It is. but with params[:domains], I receive ``` [<ActionController::Parameters {"id"=>"1", "name"=>"aaa"} permitted: false>]```. but I need to read exactly like my question. Commented Nov 2, 2020 at 10:20

1 Answer 1

2

You can permit your params with this syntax.

params.permit(:domains: %i[id name])
Sign up to request clarification or add additional context in comments.

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.