Moving from Pure Routes to Controllers


#1

I’m trying to move some logic out of my routes file and into a controller. So the controller looks like this:

@EventsController = RouteController.extend(
  template: 'home'
  subscriptions: ->
    @eventsSub = Meteor.subscribe('events')
    @peopleSub = Meteor.subscribe('people')
    return
  events: ->
    Event.find()
  people: ->
    Person.find()
  data: ->
    {
      events: @events()
      people: @people()
      ready: @eventsSub.ready
    }
)

and the route looks like this:

Router.route '/', ->
  name: 'home'
  controller:EventsController

When the page refreshes, I get nothing but there is an error on the console that says:

Route dispatch never rendered. Did you forget to call this.next() in an onBeforeAction?

This code is copied almost verbatim from Microscope. What have I missed here?

Thanks!


#2

I usually do it more like this.

UserController = RouteController.extend({
  viewProfile: function() {
    var user = Meteor.users.findOne(this.params.id);  // the id parameter
    this.render('userProfile', {
      data: user
    });
  }
});

Then in the routes part of it

Router.map(function() {
  this.route('userProfile', {
    waitOn: function() {
      return Meteor.subscribe('userProfile', this.params.id);
    },
    path: '/user/profile/:id',
    controller: 'UserController',
    action: 'viewProfile'
  })
});