Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for "global" filters #123

Open
RaphiePS opened this issue Dec 18, 2013 · 5 comments
Open

Allow for "global" filters #123

RaphiePS opened this issue Dec 18, 2013 · 5 comments

Comments

@RaphiePS
Copy link

There should be a "nice" way to have something run before all actions. For example, say I'm using connect-flash. I'd want to pass flash messages into every page, so it gets rather repetitive to have this in every controller:

controller.before('*', function(next) {
  this.messages = this.req.flash('messages');
  this.errors = this.req.flash('errors');
  // etc
  next();
});

I suppose something like this could be put in the middleware initializer, but in my mind initializers should represent application setup, not logic.

If you agree, I'd be happy to submit a pull request!

@jaredhanson
Copy link
Owner

It should be possible to do this using controller inheritance, which is viable now in 0.4, but hasn't been documented yet.

If you have another proposal for solving this, I'd be happy to consider it!

Sent from my iPhone

On Dec 17, 2013, at 10:52 PM, Raphie Palefsky-Smith [email protected] wrote:

There should be a "nice" way to have something run before all actions. For example, say I'm using connect-flash. I'd want to pass flash messages into every page, so it gets rather repetitive to have this in every controller:

controller.before('*', function(next) {
this.messages = this.req.flash('messages');
this.errors = this.req.flash('errors');
// etc
next();
});
I suppose something like this could be put in the middleware initializer, but in my mind initializers should represent application setup, not logic.

If you agree, I'd be happy to submit a pull request!


Reply to this email directly or view it on GitHub.

@RaphiePS
Copy link
Author

Didn't know that existed! Inheritance sounds perfect. I just took a glance at controller.js and couldn't find anything related to inheritance, but perhaps I didn't look hard enough.

@jaredhanson
Copy link
Owner

Take a look at instantiators/constructor.js (I think)

Sent from my iPhone

On Dec 17, 2013, at 11:17 PM, Raphie Palefsky-Smith [email protected] wrote:

Didn't know that existed! Inheritance sounds perfect. I just took a glance at controller.js and couldn't find anything related to inheritance, but perhaps I didn't look hard enough.


Reply to this email directly or view it on GitHub.

@redking
Copy link

redking commented Dec 18, 2013

Do you plan on releasing a changelog or updated docs for the latest release? I wasn't aware that controller inheritance had been added!

@jaredhanson
Copy link
Owner

Eventually, yes. But no definitive timeline.

Sent from my iPhone

On Dec 18, 2013, at 1:24 AM, Cormac Flynn [email protected] wrote:

Do you plan on releasing a changelog or updated docs for the latest release? I wasn't aware that controller inheritance had been added!


Reply to this email directly or view it on GitHub.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants