Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use :post_id rather than :id in post route definition #49

Closed
wants to merge 1 commit into from
Closed

Use :post_id rather than :id in post route definition #49

wants to merge 1 commit into from

Conversation

LBRapid
Copy link
Contributor

@LBRapid LBRapid commented Apr 6, 2014

You define the route for viewing an individual post like the following:

Blorgh.Router.map ()->
  @resource 'post', path: '/posts/:id'

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:

Blorgh.Router.map ()->
  @resource 'post', path: '/posts/:post_id'

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 馃憤 Great introduction to another JS framework for me.

@LBRapid
Copy link
Contributor Author

LBRapid commented Apr 6, 2014

@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)

@radar
Copy link
Owner

radar commented Apr 6, 2014

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 :)

@radar radar closed this in d3eade9 Apr 6, 2014
radar added a commit that referenced this pull request Apr 6, 2014
radar pushed a commit that referenced this pull request Jun 30, 2017
update rvm link in c-extensions.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants