Building a Sails Application: Ep6 - Creating a policy and adding client-side validation

Ponzi Coder · 24K views · 2013 · 4:54

Open on YouTube

Web developmenttutorialdated

Why Stack Overflow recommends it

Stack Overflow users cite it as the tutorial they were following when they hit problems with Sails policies, flash messages and jQuery setup, especially after Sails moved from 0.9 to 0.10.

Recommended by 0 people across 0 different months, 2014 to 2014.

What it is

A short screencast from Ponzi Coder's Sails.js series that builds a sample app called activityOverlord. This episode shows how to write a policy (a flash message policy) and add client-side validation to a signup form. It is part of a longer series covering authentication, policies, real-time updates and databases.

What people said

Cites Brayan Acebo · 2014-08 · Stack Overflow · on “Jquery does not work in 0.10 sails”

(Sorry for my English) I am new Sails, and I'm trying to use jquery. Following the steps in this Tutorial of YouTube [this video] . But I made ​​it through and as the tutorial is in version 0.9 and I am working on 0.10 where the linker does not exist and could not achieve using jquery. In my loyout.ejs before the <script src="/js/jquery.min.js"></script> In the view I have this structure views users new.ejs Where I'm trying to do this: <script type="text/javascript"> $(document).ready(function(){ $('#test').text('hello world'); } </script> <p id="test"> aaa </p> And in the controller UsersController.js I have this: module.exports = { new: function(req, res) { res.view(); } }; What I try to achiev

Cites DJ_Beardsquirt · 2014-09 · Stack Overflow · on “Why is my custom policy not recognized in Sails JS?”

I've been following this screencast [this video] , I've created a policy in api/policies/flash.js . I then tried making this policy usable to all of my controllers in config/policies using module.exports.policies = { '*': 'flash' }; However, when I try to access a view that requires the policy the console logs flash is not defined and my browser shows the view's path as an object. Here is the code I'm using for the policy: module.export = 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(); }; It seems like there has been a very similar problem posted on here before [LI

Cites dsp_099 · 2014-11 · Stack Overflow · on “Why does this flash policy module (express middleware) use _.clone() in Sails.js?”

From a tutorial on Sails [this video] , this is a Sails policy [LINK] - essentially Express middleware: 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'm totally lost: What's the difference between req.locals.flash and req.session.flash ? Why do the response locals.flash have to be cleared right off the bat? Why are response locals filled with cloned request session flash?