Hello Everyone,
In the next lecture Colt introduces a new format for sending data to the server from a form. Up to this point you have used the name attribute like so:
<'input type="text" name="title"> Now Colt will write it like this:
<'input type="text" name="blog[title]">
What this will do is, instead of making the value for title available directly from req.body.title it will put it inside of an object, like so: req.body.blog.title
Now all of the values from the inputs in the form get added into one object (req.body.blog) and you can easily input that data into the database simply by passing in req.body.blog to Blog.create()
Once in the POST route, the req.body.blog object will look something like this: { title: "Hello world", description: "This is a blog post" } I've commented on this further here, including the reason why we use the name="blog[title]" syntax instead of name="blog['title']" or name="blog.title" TL;DR: this syntax is specific to body-parser.
Please let me know if you have any questions by replying to the thread linked above. cheers, Ian
'Full stack development > The Web Developer Bootcamp(2020)' 카테고리의 다른 글
317. Note about RESTful Blog App: SHOW (0) | 2020.10.01 |
---|---|
316. RESTful Blog App: NEW and CREATE (0) | 2020.10.01 |
314. Blog App: Layout (0) | 2020.10.01 |
313. Note about Blog App: Layout (0) | 2020.10.01 |
312. RESTful Blog App: INDEX (0) | 2020.10.01 |