Search code examples
ember.jslink-to

Ember.js #linkTo not pulling correct property from context for dynamic segment


The linkTo helper is creating <a> tags with an href that looks like this.

 <a id="ember561 class="ember-view" href="/orgs/<Organization:ember349:17>">

The url is actually the string representation of the object. The expected functionality is to link to /orgs/17 where 17 is the id of the context object.

The context I'm passing to linkTo is a model with an id, I'm sure it has an id because I can print out this.id in the template.

  #template
  {{#each orgs}}
    {{#linkTo 'organizations.show' this}} {{this.id}} {{/linkTo}}
  {{/each}}

  #router
  Router.map ->
   @resource 'organizations', path: "/orgs", ->
    @route 'show', path: ":id"
    @route 'new'

When I click on the messed up link, it transitions to '/orgs/<Organization:ember349:17>' and that page has the correct model set.

I can print {{id}} from that template and it is correct.

ember.js version = Version: v1.0.0-rc.3-292-gbdffb37

Solution

  • Your show route needs to define the model if you're using the default serialize method. In that case I assume :organization_id

      Router.map ->
        @resource 'organizations', path: "/orgs", ->
          @route 'show', path: ":organization_id"
          @route 'new'