0
votes

The code works and here is the jsfiddle for the code. But, I don't like the approach I am using to get {[render}} to work. For now to be able to use {{render events}} in application-template, I need to set it in the application-route using setupController and then calling controllerFor('events'), otherwise it won't work. But I have already defined an EventsRoute with a model hook for setting up the controller content and will prefer for {{render helper}} to use the model set in the EventsRoute.

I was wondering if there is a better or more idiomatic way to do this in ember besides my present approach of going to ApplicationRoute.

Relevant code*

  App.Router.map(function(){
    this.resource('events');
  });

The {{render 'events'}} in application template only works when i set the model via application route.

 App.ApplicationRoute = Ember.Route.extend({
   setupController: function(){
     this.controllerFor('events').set('model', App.Event.find());        
   }
 });

I would prefer to {{render 'events'}} to work with the content set here but it doesn't. But I am keeping for now to use in places where it might make sense to use {{#linkTo}}.

 App.EventsRoute = Ember.Route.extend({
    model: function(){
    return App.Event.find();  
    },

   setupController: function(controller, model){ 
         controller.set('content', model);
    }
});

The templates

   <script type="text/x-handlebars" data-template-name="application">
     {{render 'events'}}
      {{outlet}}
  </script>

  <script type="text/x-handlebars" data-template-name="events">

        <button {{action 'yEmpty'}}> log event content is empty</button>

       {{#each controller}}
        <h3>{{title}}</h3>
       <p>{{start}} - {{end}}</p> 
      {{/each}}
    {{outlet}}
 </script>
1

1 Answers

0
votes

I'm unsure of what you're trying to do. Do you want events and appointments to be rendered at the same time on one page? If yes, then, I think, you need to use render (much like you do in your jsfiddle). If not, you could remove {{render 'events'}} and setupController hook on ApplicationRoute and redirect to events route.

I found this issue with Fixture Adapter and looks like it doesn't work with hasMany (therefore jsfiddle example won't work) but I assume you are using RESTAdapter.

UPDATE:

Another place to set the model is in init hook like so:

App.EventsController = Ember.ArrayController.extend({
  init: function () {
    this.set('model', App.Event.find());
  }
});

Personally, I would left the code in setupController hook.