Last active
June 2, 2016 15:40
-
-
Save cssimms/5e00f43f1c6f106618666f28c767f32e to your computer and use it in GitHub Desktop.
Strong Parameters in Nodal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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