Note that there are some explanatory texts on larger screens.

plurals
  1. POEmber.js Dynamic segment not working
    primarykey
    data
    text
    <p>I'm using Ember 1.0.0 and the latest build of Ember Data (beta), and I have a route with a dynamic segment that isn't working.</p> <p>I have defined the routes below:</p> <pre><code>PwdMgr.Router.map(function() { this.resource("passwords", function(){ this.resource("password", {path: "/:password_id"}, function(){ this.route("edit"); }); }); } </code></pre> <p>In the template passwords.index I display a list of models like this:</p> <pre><code>{{#each}} &lt;tr&gt; &lt;td&gt;{{id}}&lt;/td&gt; &lt;td&gt;{{name}}&lt;/td&gt; &lt;td&gt;{{client.name}}&lt;/td&gt; &lt;td&gt;{{service.name}}&lt;/td&gt; &lt;td&gt;{{localisation.name}}&lt;/td&gt; &lt;td&gt;{{status.name}}&lt;/td&gt; &lt;td&gt;{{login}}&lt;/td&gt; &lt;td&gt;{{password}}&lt;/td&gt; &lt;td&gt; {{#link-to 'password.index' this}}&lt;span class="glyphicon glyphicon-search"&gt;&lt;/span&gt;{{/link-to}} {{#link-to 'password.edit' this}}&lt;span class="glyphicon glyphicon-pencil"&gt;&lt;/span&gt;{{/link-to}} &lt;span class="glyphicon glyphicon-remove" {{action 'edit' password}}&gt;&lt;/span&gt; &lt;/td&gt; &lt;/tr&gt; {{/each}} </code></pre> <p>I have two links, one that goes to the route password.index and one to the route passwword.edit. I provide the model for the dynamic segment and the handlebars creates the URL correctly (/passwords/1 and /passwords/1/edit).</p> <p>My problem is that when I get to the URL /password/1 (or /password/1/edit), the model is not a single object but an array of objects.</p> <p>Since I'm using the default pattern, as explained in the guides, I didn't setup Route objects. But for debugging purposes I created a route object for the password.index route. Here's what it looks like:</p> <pre><code>PwdMgr.PasswordIndexRoute = Ember.Route.extend({ model: function(params){ console.log(params); return this.get('store').find('password',params.password_id); }, setupController: function(controller, model){ console.log(model); } </code></pre> <p>});</p> <p>And here's my console log:</p> <pre><code>Object {} app.js (line 31) &lt;DS.RecordArray:ember435&gt; { content=[3], store=&lt;DS.Store:ember506&gt;, isLoaded=true, more...} app.js (line 35) </code></pre> <p>The empty object explains why I get an array of object but is there a reason why the params variable is an empty object?</p> <p>Thanks a lot</p> <p>[EDIT]</p> <p>I have changed my Router.map like so:</p> <pre><code>PwdMgr.Router.map(function() { this.resource("passwords", function(){ this.route("detail", {path: "/:password_id"}); this.route("edit", {path: "/:password_id/edit"}); }); }): </code></pre> <p>And the dynamic segment for both "detail" and "edit" routes works fine. I think the problem comes from the fact that the dynamic segment is in the nested resource, which is strange because the Emberjs guides' examples are with dynamic segments in nested resources.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload