I have a route that represents a single group of users. Since it represents one group (and its parent all groups), I am using an ObjectController. Within this group the current user is able to add other users to the group. So among other things I need to sort all of the users by name, but unlike array controllers, object controllers do not have the sortBy method. This route represents a single group, so it wouldn’t make sense to have the controller type reflect this list of users that can be added.
Are there other methods for sorting objects in Ember by their properties, without using the sortBy method in array controllers?
Is there a better way to break this up so that the list of friends can have its own (array) controller and be included in the group template?
Essentially, yes. Though, to clarify: the other controller does not need to be a controller associated with another route. It can be any named controller.
So, even if you did not have a Carpoolers route anywhere, this would still work:
Because controller is just a presenter for model, it’s better to keep each controller a single responsibility.
In this case you need 2 controllers, an ObjectController for group and an ArrayController for users. Then you can use render to display a list of users in group’s template.
var GroupController = Em.ObjectController.extend();
var UserController = Em.ArrayController.extend({
sortProperties: ['name']
});