Domanda

How can I allow a JSON array POST to my API endpoint through strong parameters?

Assuming I have the following JSON:

{ "objects": [ { "attr1": "hi", "attr2": "hi2" }, { "attr1": "hi", "attr2": "hi2" } ] }

How can I get Rails to fit this into its params? I currently get an obscure Unprocessed Entity response when I post the request to my create action.

I have tried both params.require(:objects) and params.require(objects: []), to no luck. Any ideas?

È stato utile?

Soluzione

Turns out I had a silly typo in my Content-Type header.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top