>> I disagree that “there’s no need for the submitting JS to know anything about the root key”
I should clarify that I wasn't expressing an opinion either way, but rather summarizing what it seemed DHH was saying. On Thu, Feb 26, 2015 at 12:10 PM, Jason Fleetwood-Boldt < [email protected]> wrote: > > > Unless I’m misreading it the JSON API (http://jsonapi.org/format/), > currently being worked on by Katz and others, specifies that submitted > resources should look like this: > > POST /photos Content-Type: application/vnd.api+json Accept: > application/vnd.api+json { "data": { "type": "photos", "title": "Ember > Hamster", "src": "http://example.com/images/productivity.png" } } > > > Since this is an industry-wide effort to move towards a common structure > for all client-server communication across an endpoint, I think Rails > should follow suit and move in this direction. > > I disagree that “there’s no need for the submitting JS to know anything > about the root key” — there are lots of use cases for the submitting JS to > include additional things (like a token) or some other kind of non-resource > oriented meta data. Root keys help keep things clean, I would say not using > them is a code smell/borderline antipattern. > > -Jason > > > > > > On Feb 26, 2015, at 11:47 AM, James Coleman <[email protected]> wrote: > > Wojciech seems to be asking why the params structure in the actual HTTP > request is different between JSON and HTML, and I think I can answer that. > > Basically, the difference is that with an HTML request, the URL params and > the "form" params are merged. Hence the need to keep the two separate via a > root key. But with JSON, presumably only the real params are submitted as > JSON, so they're already separate, and there's then no need for the > submitting JS to know anything about the root key. > > Is that a correct summary? > > On Thu, Feb 26, 2015 at 11:36 AM, DHH <[email protected]> wrote: > >> Yes, same controllers. That's the case this was invented for. >> >> On Wednesday, February 25, 2015 at 12:14:04 PM UTC-8, Wojciech Wnętrzak >> wrote: >>> >>> Are you using the same controller for HTML and JSON responses? >>> Since we have strong params, model attributes can be nicely grouped with >>> or without root key. >>> I didn't try it, but HTML attributes could be passed flat as well to be >>> consistent with JSON format. >>> In that case, you wouldn't need such tricks with params wrapping. >>> >>> >> -- >> 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 [email protected]. >> To post to this group, send email to [email protected]. >> Visit this group at http://groups.google.com/group/rubyonrails-core. >> For more options, visit https://groups.google.com/d/optout. >> > > > -- > 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 [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/rubyonrails-core. > For more options, visit https://groups.google.com/d/optout. > > > -- > 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 [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/rubyonrails-core. > For more options, visit https://groups.google.com/d/optout. > -- 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/d/optout.
