As someone who is new to the world of Ember.js, I'm feeling quite confused about a specific aspect. I am wondering if there is a way to utilize a variable controller when navigating routes in Ember.js?
Let me provide some context:
Imagine I have a collection of models that need to be managed by different controllers and displayed using distinct templates. For instance, if I have a route like items/:item_id
, and I wish to implement something along these lines:
App.ItemRoute = Ember.Route.extend({
model: function(params) {
return items[params.lesson_id]; // edit: should be item_id not lesson_id
},
setupController: function(controller, model) {
controller.set("model", model);
},
renderTemplate: function(controller, model) {
this.render(model.template || "item", {
controller: model.controller || "ItemController"
});
}
});
The ember guides available at
demonstrate the use of this.render
with a controller option, however, whenever I input anything (even "ItemController"
), I encounter the following error:
Error while loading route: Error: You passed controller: 'ItemController' into the render method, but no such controller could be found.
Is there a more effective approach to tackle this issue?