Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // routes/application.js
- import Ember from 'ember';
- export default Ember.Route.extend({
- model(){
- return this.store.findAll('user');
- },
- actions: {
- test(name){
- this.store.createRecord('user', {
- username: name,
- email: 'email@email.com',
- is_staff: false
- }).save();
- }
- }
- });
- {
- "data": {
- "type": "User",
- "id": null,
- "attributes": {
- "username": "bill",
- "email": "email@email.com",
- "is_staff": false
- }
- }
- }
- {
- data:
- {
- attributes:
- {
- username: "bill",
- email: "email@email.com",
- is-staff: false
- },
- type: "users"
- }
- }
- import DS from 'ember-data';
- export default DS.JSONAPISerializer.extend({
- normalizeCreateRecordResponse(store, type, payload){
- return {
- data: {
- type: 'User',
- id: null,
- attributes: {
- username: payload.username,
- email: payload.email,
- is_staff: payload.is_staff
- }
- }
- }
- }
- });
- // routes/application.js
- import Ember from 'ember';
- export default Ember.Route.extend({
- model(){
- return this.store.findAll('user');
- },
- actions: {
- test(name){
- Ember.$.post('http://localhost:8000/api/users/', {
- username: name,
- email: 'email@email.com',
- is_staff: false
- });
- }
- });
Add Comment
Please, Sign In to add comment