Skip to content
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 828a26f commit f31e9a99b2b5930bcb163aabac14f4560813eb8a
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 f31e9a9

Please sign in to comment.
You can’t perform that action at this time.