I've written an API with Rails and need to accept some nested_attributes in API calls.
Currently I send data via
PATCH /api/v1/vintages/1.json
{
"vintage": {
"year": 2014,
"name": "Some name",
"foo": "bar",
"sizes_attributes": [
{
"name": "large",
"quantity": "12"
},
{
"name": "medium",
"quantity": "2"
}
]
}
}
However, I'd like to perform the following:
PATCH /api/v1/vintages/1.json
{
"vintage": {
"year": 2014,
"name": "Some name",
"foo": "bar",
"sizes": [
{
"name": "large",
"quantity": "12"
},
{
"name": "medium",
"quantity": "2"
}
]
}
}
The difference being attributes being part of the key of the fields. I want to be able to accept_nested_attributes_for :sizes without having to use _attributes be a part of the JSON object.
Anyone know how to manage this?
params[:vintage][:sizes_attributes] = params[:vintage][:sizes]to rename them.