Guest User

Untitled

a guest
Dec 10th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. // routes/application.js
  2.  
  3. import Ember from 'ember';
  4.  
  5. export default Ember.Route.extend({
  6. model(){
  7. return this.store.findAll('user');
  8. },
  9. actions: {
  10. test(name){
  11. this.store.createRecord('user', {
  12. username: name,
  13. email: 'email@email.com',
  14. is_staff: false
  15. }).save();
  16. }
  17. }
  18. });
  19.  
  20. {
  21. "data": {
  22. "type": "User",
  23. "id": null,
  24. "attributes": {
  25. "username": "bill",
  26. "email": "email@email.com",
  27. "is_staff": false
  28. }
  29. }
  30. }
  31.  
  32. {
  33. data:
  34. {
  35. attributes:
  36. {
  37. username: "bill",
  38. email: "email@email.com",
  39. is-staff: false
  40. },
  41. type: "users"
  42. }
  43. }
  44.  
  45. import DS from 'ember-data';
  46.  
  47. export default DS.JSONAPISerializer.extend({
  48.  
  49. normalizeCreateRecordResponse(store, type, payload){
  50. return {
  51. data: {
  52. type: 'User',
  53. id: null,
  54. attributes: {
  55. username: payload.username,
  56. email: payload.email,
  57. is_staff: payload.is_staff
  58. }
  59. }
  60. }
  61. }
  62.  
  63. });
  64.  
  65. // routes/application.js
  66.  
  67. import Ember from 'ember';
  68.  
  69. export default Ember.Route.extend({
  70. model(){
  71. return this.store.findAll('user');
  72. },
  73. actions: {
  74. test(name){
  75. Ember.$.post('http://localhost:8000/api/users/', {
  76. username: name,
  77. email: 'email@email.com',
  78. is_staff: false
  79. });
  80. }
  81. });
Add Comment
Please, Sign In to add comment