Note that there are some explanatory texts on larger screens.

plurals
  1. POember.js: How to initialize a controller with generateController
    text
    copied!<p>I need to insert the view &amp; controller from the route <code>categories</code> in multiple other routes, without nesting them in that <code>categories</code> route (because I want to keep URLs independent).</p> <p>So, I'm rendering the <code>categories</code> template, into the main <code>application</code> one, in the outlet <code>topbar</code> using the controller I get from my existing <code>categories</code> route.</p> <pre class="lang-js prettyprint-override"><code>App.PostRoute = Ember.Route.extend({ renderTemplate: function() { this.render(); this.render('categories', { outlet: 'topbar', into: 'application', controller: this.controllerFor('categories') }); } }); </code></pre> <p>When I visit the <code>categories</code> route, all's working fine! I can even browse other routes from there. But if I access first any other route, the <code>categories</code> controller seems not to be created:</p> <blockquote> <p>Assertion failed: The controller for route 'categories'' could not be found. Make sure that this route exists and has already been entered at least once. If you must intialize the controller without entering a route, use `generateController`.</p> </blockquote> <p>Nice warning :) I wish all frameworks were that smart! So I'm trying to generate that controller manually... But how?</p> <p>I tried:</p> <pre class="lang-js prettyprint-override"><code>App.CategoriesRoute.create().generateController('categories', App.Category) </code></pre> <p>and the static version:</p> <pre class="lang-js prettyprint-override"><code>App.CategoriesRoute.generateController('categories', App.Category) </code></pre> <p>It doesn't seem to be the right way to do. Any help please?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload