0
votes

I have been told time and time again to "never use .create() on a controller/ObjectController because Ember will do it for [me]". I am confused as to how I then can add an item to an ArrayController without first creating it.

In my case, I am using a Controller (not an ObjectController) as an itemController for an ArrayController since it is not backed by AJAX-loaded data (...is this the correct usage?). I would like to add an instance of my itemController to the ArrayController, but I can't figure out how to do that without first creating the item to be added.

JSBin here: http://emberjs.jsbin.com/momikuto/17/edit

TL;DR: I don't know how to add a Post object to the ArrayController without the .create() in the addPost function.

1

1 Answers

1
votes

Models vs Controllers

I think the primary confusion here is between models and controllers. A controller can decorate a model to add display attributes but isn't the primary data object.

A model can be a simple JSON object, or it could be full-blown ember-data.

So, yes Ember will create your controllers for you. And you specify the model(s) for the controller somehow (see below).

Setting Controller Data

So in your example you are trying to seed your controller with two static posts id:1, id:2. This is probably best done in the Route as opposed to the View.