Navigation Menu

Skip to content

Commit

Permalink
Hook routes into post model
Browse files Browse the repository at this point in the history
This acceptance test error drives a lot of logic: to display the post's titl
e 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 ho
ok.

Outer red: No model was found for 'post'

With this logic added, the acceptance test errors out quickly: there _is_ no
 `post` model.
  • Loading branch information
Josh Justice committed Jan 12, 2018
1 parent cdfc232 commit 306ca7e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
7 changes: 5 additions & 2 deletions app/controllers/posts/new.js
Expand Up @@ -2,8 +2,11 @@ import Controller from '@ember/controller';

export default Controller.extend({
actions: {
savePost() {
this.transitionToRoute('posts.show');
savePost(postData) {
let post = this.store.createRecord('post', postData);
post.save().then((post) => {
this.transitionToRoute('posts.show', post.id);
});
}
}
});
2 changes: 1 addition & 1 deletion app/router.js
Expand Up @@ -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' });
});
});

Expand Down
3 changes: 3 additions & 0 deletions app/routes/posts/show.js
@@ -1,4 +1,7 @@
import Route from '@ember/routing/route';

export default Route.extend({
model(params) {
return this.store.findRecord('post', params.id);
}
});

0 comments on commit 306ca7e

Please sign in to comment.