0

In my controller I define

PagesController.before('*', function(next) {
  console.log('zip');
  next();
});

And in routes.js I have

this.resources('pages', { only: [ 'index'] })

The "before" filter wasn't being executed. It looks like the code in the controller is being executed before the resources call, and so at the time the before filter is set up the array of actions is empty. Is this expected, and if so where should the before filter be specified (and would it be worth a warning in the docs). Or is this unexpected, in which case any suggestions for why this is happening?

1 Answers1

2

Make sure your filter is at the bottom of your controller. :)

wridgers
  • 717
  • 1
  • 5
  • 8
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient [reputation](http://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](http://stackoverflow.com/help/privileges/comment). – Spontifixus Aug 29 '13 at 12:29
  • I was just banging me head on this for 30 minutes. Moving to the bottom was an immediate fix. Thanks @stacky – brock Aug 29 '13 at 16:03
  • Thanks stacky, that produced the correct behaviour. But it still seems a bit fragile to require something that "looks" declarative to be defined in a particular place, particularly when something like a "before" statement feels like it should naturally appear at the top of the controller. IMHO it would be better if Locomotive handled something like this lazily, i.e. just record the 'wildcard before' statement internally and then do something with it once the action set is known. – user2711129 Aug 29 '13 at 16:16