0
votes

When using {{render "modelHandler" model}} the corresponding controller's model function is never called.

Reproduced here: http://jsbin.com/EVoXAceP/3/edit

I'm 90% sure this is a bug. I'm posting this here before I post to github in case there is something obvious I've missed or "I'm doing it wrong." In either case, if you could kindly point me in the right direction.

Use Case (Why I need this to work in the first place).

I'm using {{render}} to include an AddressAdd template, for which I need to extend the model to include a list of states as well as the default state. While I could load the states onto the parent model (say a property or a contact card), since many views include an AddressAdd I'd like to avoid having to manually add the information for the drop down each time.

So if you also happen to know a better way of implementing this besides {{render}} and the controller's model hook, please let me know!

2

2 Answers

1
votes

It isn't a bug, the model hook is only fired when you visit the url associated with that route, and it lives on the route, not on a controller. Additionally, if your controller has a model on it it should be an ObjectController (unless it's an array, then it's an ArrayController).

http://jsbin.com/EVoXAceP/13/edit

When you call render you are saying you want to render a particular template using a particular context.

I would create a route underneath the route you're in and use a link-to without a model, which will cause the model hook to fire.

1
votes

In your application template

{{ render 'foo' bar }}

shouldn't you have a bar property in the ApplicationController?

App.ApplicationController = Ember.Controller.extend({
  bar: {isBar: 'yup'}
});