Gabriel Sobrinho
2013-Nov-11 16:53 UTC
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? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscribe@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at http://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/groups/opt_out.
Rafael Mendonça França
2013-Nov-11 16:54 UTC
Re: Child index on validations - accepts_nested_attributes_for
https://github.com/rails/rails/pull/8638 Rafael Mendonça França http://twitter.com/rafaelfranca https://github.com/rafaelfranca On Mon, Nov 11, 2013 at 2:53 PM, Gabriel Sobrinho < gabriel.sobrinho@gmail.com> wrote:> 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? > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Core" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to rubyonrails-core+unsubscribe@googlegroups.com. > To post to this group, send email to rubyonrails-core@googlegroups.com. > Visit this group at http://groups.google.com/group/rubyonrails-core. > For more options, visit https://groups.google.com/groups/opt_out. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscribe@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at http://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/groups/opt_out.
Gabriel Sobrinho
2013-Nov-11 17:01 UTC
Re: Child index on validations - accepts_nested_attributes_for
Awesome, waiting for this! On Monday, November 11, 2013 2:54:42 PM UTC-2, Rafael Mendonça França wrote:> > https://github.com/rails/rails/pull/8638 > > Rafael Mendonça França > http://twitter.com/rafaelfranca > https://github.com/rafaelfranca > > > On Mon, Nov 11, 2013 at 2:53 PM, Gabriel Sobrinho <gabriel....@gmail.com<javascript:> > > wrote: > >> 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? >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Ruby on Rails: Core" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to rubyonrails-co...@googlegroups.com <javascript:>. >> To post to this group, send email to rubyonra...@googlegroups.com<javascript:> >> . >> Visit this group at http://groups.google.com/group/rubyonrails-core. >> For more options, visit https://groups.google.com/groups/opt_out. >> > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscribe@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at http://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/groups/opt_out.