Permalink
Browse files

Hook routes into post model

This acceptance test error drives a lot of logic: to display the post's title on the show page, we need to save the post on the new page, include the ID in the transition to the show route, then load the post on the show page's model hook.

Outer red: Uncaught TypeError: Cannot read property 'create' of undefined

This isn't a very descriptive error, but it seems to be related to the fact that there _is_ no `post` model.
  • Loading branch information...
CodingItWrong committed Jan 11, 2018
1 parent ee28323 commit 1d73f62ffae886202d2ecc094a8ee5211b39f9d8
Showing with 8 additions and 3 deletions.
  1. +4 −2 app/controllers/posts/new.js
  2. +1 −1 app/router.js
  3. +3 −0 app/routes/posts/show.js
@@ -2,8 +2,10 @@ import Controller from '@ember/controller';
export default Controller.extend({
actions: {
savePost() {
this.transitionToRoute('posts.show');
async savePost(postData) {
let post = this.store.createRecord('post', postData);
await post.save();
this.transitionToRoute('posts.show', post.id);
}
}
});
@@ -9,7 +9,7 @@ const Router = EmberRouter.extend({
Router.map(function() {
this.route('posts', function() {
this.route('new');
this.route('show');
this.route('show', { path: ':id' });
});
});
@@ -1,4 +1,7 @@
import Route from '@ember/routing/route';
export default Route.extend({
model({ id }) {
return this.store.findRecord('post', id);
}
});

0 comments on commit 1d73f62

Please sign in to comment.