Skip to content

Instantly share code, notes, and snippets.

@fivetanley
Last active August 29, 2015 14:25
Show Gist options
  • Save fivetanley/5a2208b2e38c7742630d to your computer and use it in GitHub Desktop.
Save fivetanley/5a2208b2e38c7742630d to your computer and use it in GitHub Desktop.
yo iheanyi
import Ember from 'ember';
const {Promise} = Ember.RSVP;
export default Ember.Route.extend({
model() {
var slug = params.id;
return new Promise((resolve, reject) => {
$.getJSON(`/api/posts/${slug}`).then((payload) => {
let id = payload.post.id;
let postAdapter = this.store.serializerFor('post');
let Post = this.modelFor('post');
let normalized = postAdapter.normalize(Post, payload);
this.store.push(normalized);
resolve(this.store.findRecord('post', id));
}).catch(reject);
});
}
});
{
"post": {
"id": 1,
"name": "Iheanyi is a rad person who's going to go places"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment