Frage

Following this screencast, I've created a policy in api/policies/flash.js. I then tried to use this policy in config/policies where at the beginning of the file I've used '*':flash so all my controllers would use this policy, however every time I tried to start Sails after this I got the error that flash is undefined. The code I've used in the aforementioned policy is this:

module.exports = function(req, res, next) {

res.locals.flash = {};

if(!req.session.flash) return next();

res.locals.flash = _.clone(req.session.flash);

// Clear flash
req.session.flash = {};

next();

};

I've also tried (like in the example in config/policies.js) module.exports = function flash(req, res, next)... and it also got the same error. In the screencast mentioned above the same steps did work perfectly. I've checked and rechecked to make it wasn't something I missed and couldn't find anything. I imagine it might be a version issue.

Can anyone clarify what I'm doing wrong?

Many thanks

War es hilfreich?

Lösung

Everything seems good except that in your config/policies.js it should be 'flash' with apostrophes:

module.exports.policies = {
  '*': 'flash'
};
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top