Skip to content

Instantly share code, notes, and snippets.

@cktricky
Last active January 2, 2016 15:59
Show Gist options
  • Save cktricky/8327287 to your computer and use it in GitHub Desktop.
Save cktricky/8327287 to your computer and use it in GitHub Desktop.
Mass Assignment Part 2

##Web Application Code##

Within the request handling code:

_ = require('underscore');
var user = new User(_.pick(req.body, User.userCreateSafeFields));

Within the User model:

UserSchema.statics = {
    User.userCreateSafeFields: ['email', 'password', 'password_confirmation', 'first_name', 'last_name']
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment