0
votes

I am trying to get my head around Ember.js and I have a CRUD ember application that currently has two models- user and subject. A user can be associated with many subjects. My router.js looks like this:

App.Router.map(function(){
  this.resource('users', function(){
    this.resource('user', { path:'/:user_id' }, function(){
      this.route('edit');
    });
    this.route('create');
  });

  this.resource('subjects', function(){
    this.resource('subject', {path: '/:subject_id'}, function(){
        this.route('edit');
    });
    this.route('create');
  });

});

Each subject has a number of categories, which will also have CRUD functionality, so I now need to implement a categories model. My question is, what would be the most effective way of modelling the routing for the categories? Should I define it as a separate route structure or as a resource within the subjects routing? I have attempted the latter but it messed up my entire app and nothing rendered in the browser. Any suggestions/ links to examples very much appreciated.

EDIT: Categories routing

App.CategoriesRoute = Ember.Route.extend({
  model: function(){
    return this.store.find('category');
  }
});

App.CategoryRoute = Ember.Route.extend({
  model: function(params) { 
    return this.store.find('category', params.category_id);
  }
});
1
can you tell me how exactly you defined categories route and which url you accessed - Hardik127
I'm not sure what you mean by which url I accessed? - bookthief
url you got in browser. - Hardik127
can one category belong to many subjects? If category and subject has many to many relationship then separate route structure would be better. - Hardik127
A category can only belong to one subject but a subject can have many categories. I have implemented them separately for now anyway - bookthief

1 Answers

1
votes
App.Router.map(function(){
  this.resource('users', function(){
    this.resource('user', { path:'/:user_id' }, function(){
      this.route('edit');
    });
    this.route('create');
  });

  this.resource('subjects', function(){
    this.resource('subject', {path: '/:subject_id'}, function(){
        this.route('edit');
        this.resource('categories', function(){
          this.resource('category', , {path: '/:category_id'})'
        });
    });
    this.route('create');
  });

});