Child index on validations - accepts_nested_attributes_for

Hey guys,

I have a situation where I’m creating a object which have some items and the items have a validation that need to be executed on the server side but rails do not map these validation messages to the specific child.

A contrived example may be a invoice which have 2 items and for some reason the product of one of these items is not allowed to be inserted:

POST /invoices?invoice[items_attributes][0][product_id]=1&invoice[items_attributes][1][product_id]=2

The JSON response when the validation fails is something like:

{“items.product”:[“is not allowed”]}

But for which item the validation failed? For this JSON response, I can’t guess if it was the first or the second nor both items.

I was thinking in something like:

{“items.1.product”:[“is not allowed”]}

Where the 1 is the child index (can’t use the id because we do not have it for new records).

That’s a proposal but we may implement something else.

Suggestions?

https://github.com/rails/rails/pull/8638

Awesome, waiting for this!