0
votes

I have a rather complex router in my application and I'm having a weird issue with deep nesting my routes and resourses.

The problematic part of my router is as follows:

this.resource('condominiums', function(){
        this.route('index', {path: '/'});
        this.route('new');
        this.route('edit', {path: 'edit/:id'});
        this.resource('condominium', {path: '/condominium/:id'}, function(){
            this.resource('blocks', {path: '/blocks'}, function(){
                this.resource('block', {path: '/block/:id'}, function(){
                    this.resource('units', {path: '/units'}, function(){
                    });
                });
            });
        });
    });

My templates nest each other properly as far as I can tell and everything works until I try and use a link-to in the deepest section that I have:

{{#each block in blocks}}
  <tr>
    <td>
    {{#link-to 'block.index' block}}{{block.name}}{{/link-to}}
    </td>
  </tr>
{{/each}}

The problem is the the dynamic segments seem to be wrong and the URL is being built always based on the ID of the block changing the ID of the condominium as well as the ID of the block when only the id of the block should change.

The result is a URL like: condominiuns/2/blocks/2

Instead of the correct : condominiuns/1/blocks/2

I have tried passing 2 models to the link-to helper and the same thing happens. Thank you in advance!

1
Please recreate your problem in jsbin and post the linkSusai

1 Answers

1
votes

You'll want to rename the dynamic segments of your paths. It's conventional to use the resource name as the prefix to id. Some excerpts from your example rewritten:

this.resource('condominium', {path: '/condominium/:condominium_id'} //...

this.resource('block', {path: '/block/:block_id'} //...