Skip to content

Instantly share code, notes, and snippets.

@cssimms
Last active June 2, 2016 15:40
Show Gist options
  • Save cssimms/5e00f43f1c6f106618666f28c767f32e to your computer and use it in GitHub Desktop.
Save cssimms/5e00f43f1c6f106618666f28c767f32e to your computer and use it in GitHub Desktop.
Strong Parameters in Nodal
//TL:DR Strong Params
npm install -g nodal
nodal new tldr-strong-params
// enter your name as author
cd tldr-strong-params
//start nodal server in new tab
nodal s
nodal g:model Member
nodal g:controller --for Member
nodal db:create
nodal db:prepare
nodal db:migrate
//send a post request to add a member and age
//send a get request to see your member in the db
// calling .permit on the params body will define which params you want the controller to accept
// first we permit the 'name' data
create() {
Member.create(this.params.body.permit('name'), (err, model) => {
this.respond(err || model);
});
}
// then post a new user, add in whatever age you'd like - the age data doesn't make it to the database
// alternatively, we could use .except for the opposite effect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment