Closed LBRapid closed 10 years ago
@radar
In fact, using :post_id in other places seems to make other things work without much effort as well, such as editing the post.
Changing
Blorgh.Router.map ()->
@resource 'post', path: '/posts/:id'
@resource 'posts.new', path:'/posts/new'
@resource 'posts.edit', path: '/posts/:id/edit'
to
Blorgh.Router.map ()->
@resource 'post', path: '/posts/:post_id'
@resource 'posts.new', path:'/posts/new'
@resource 'posts.edit', path: '/posts/:post_id/edit'
completely prevents the need to create a model method in Blorgh.PostsEditRoute
, thus shortening it to:
Blorgh.PostsEditRoute = Ember.Route.extend
actions:
save: ->
route = this
this.currentModel.save().then (model) ->
route.transitionTo('post', model)
Thanks @LBRapid :) I suspected something like this, but I wasn't sure. A lot of the guides I was reading were just saying to use something like :post_id
vs. :id
and I thought it was more conventional than it doing something good. It's good to get confirmation of this. I really appreciate that :)
You define the route for viewing an individual post like the following:
This route is not incorrect in and of itself, but it won't automatically try to use the find method defined on the post model. For that to happen, it needs to be defined using
:post_id
rather than:id
, like so:More info in the dynamic segments section of the ember routing guide at http://emberjs.com/guides/routing/defining-your-routes/
Otherwise, this is a really awesome guide :+1: Great introduction to another JS framework for me.