Ember route loading wrong controller

180 views Asked by At

This is part of my router

App.Router.map(function () {
  this.resource('report', {path: '/noticia/:report_id'}, function() {
    this.route('pictures');
  });
});

I have defined an App.ReportPicturesController but my route App.ReportPicturesRoute insists on loading a different controller.

If I do not specify a model hook, it load the App.ReportController, and if I load the model I need (that is called comment) in loads the App.CommentController.

I've tried to set controllerName to reportPictures but it didn't work.

What I have to do to make the route load ReportPicturesController? Why is not loaded the expected controller?

EDIT: If it makes any difference, I'm using ember 1.8.1, ember-data 1.0.0-beta.12, and this is what the route looks like,

App.ReportPicturesRoute = Ember.Route.extend({
  model: function(params) {
    var report = this.modelFor('report');
    return this.store.createRecord('comment', {
      inReplyToStatus: report
    });
  }
});

EDIT2: The full source code is at https://github.com/camolin3/tweetsaster

2

There are 2 answers

3
Timo On

It is working as expected when I try.. have a look:

http://emberjs.jsbin.com/rayoje/2/

1
Christian On

You are missing the ReportRoute model hook implementation similar to this

App.ReportRoute = Ember.Route.extend({
    model: function(params) {
        return {id:params.report_id}; 
        //or with ember-data return this.store.find('report', params.report_id);
    }
});