Confusion around how to create resources?


#1

I am new to Ember JS. I’m trying to figure out how to create URLs like:

http://myapp.com/admin/user-groups/group_name

Note: group_name in the URL is dynamic.

This is how my router file looks like (I am using the Ember CLI).

this.resource('admin' function() {
    this.resource('user-groups', { path: '/user-groups/:group_name' });
});

The above code works but, causes some issues with my templates where some properties do not show up. Also, I get the following error in the console:

cannot read property shouldSupercede of undefined

I read Is there really no way to make an optional dynamic segment in Ember? and realized it had to do with my router file so I made the user-groups resource its own line. Now, other templates load with the missing data but, the URL above does not work. I know I’m not declaring the route and resource the right way. What am I missing? How do I create the route / resource such that the URL above would work?


#2

I believe you should be doing this.

this.resource('admin' function() {
    this.route('user-groups', { path: '/user-groups/:group_name' });
});

Unless you intend on having multiple routes within the user-groups resource, in which case

this.resource('admin' function() {
    this.resource('user-groups', function(){
         this.route('single', { path: '/:group_name' });
    });
});