rhodee
rhodee

Reputation: 1267

Confusion about naming conventions in emberjs

Perhaps some folks just know the answer, but I am trying to understand the following:

Say you are declaring a view:

App.FooView = Ember.View.extend({});

Now referencing this view in App.Router results in the following error:

router.get('applicationController').connectOutlet('Foo')

When I reference Foo the console states: Uncaught Error: assertion failed: The name you supplied Foo did not resolve to a controller FooController

I could not find anywhere in the docs explaining the args. Perhaps the person who downvoted could actually contribute to the solution.

Upvotes: 1

Views: 681

Answers (1)

buuda
buuda

Reputation: 1427

When you connect an outlet, the router looks for both a controller and a view the having the same name as the one supplied. In the example you listed, the router is looking for a FooController and a FooView, and is not finding the controller. If you would like to specify more details you can pass an options object with the view, controller and context, like so:

router.get('applicationController').connectOutlet( {
           outletName: 'master',
           controller: 'fooController',
           view: 'fooView',
           context: data
        }); 

From the documentation:

connectOutlet: function(name, context) {
// Normalize arguments. Supported arguments:
//
// name
// name, context
// outletName, name
// outletName, name, context
// options
//
// The options hash has the following keys:
//
//   name: the name of the controller and view
//     to use. If this is passed, the name
//     determines the view and controller.
//   outletName: the name of the outlet to
//     fill in. default: 'view'
//   viewClass: the class of the view to instantiate
//   controller: the controller instance to pass
//     to the view
//   context: an object that should become the
//     controller's `content` and thus the
//     template's context.

edit: grammar and code format

Upvotes: 1

Related Questions