简体   繁体   中英

How to format json in Ember Data for Rails API?

I'm using Ember 2.3 with Ember Data but am having trouble getting data to save to my rails server. It appears that the data isn't formatted properly for what the server is expecting.

The data that works (from a scaffolding app) looks like this:

{name: "Clinic Demo", code: "CLN", position: 4}

This is what Ember Data sends:

{"data":{"attributes":{"name":"Clinic Demo","code":"CLN","position":5},"type":"clinics"}}

Should I look at serializers or change what the server expects? A Serializer might be the answer. The adapter configured does hit the server, but isn't expecting this type of json data. Does the active-model-adapter correct this?

Also ember is returning this very non-descript error:

Error: The adapter rejected the commit because it was invalid

Yes, you should use active-model-adapter maintained by Ember Data organisation. All instructions how to use can be found in README .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM