Bummer! This is just a preview. You need to be signed in with a Pro account to view the entire video.
Updating Entries in a Table2:48 with Andrew Chalkley
In this video we'll update rows of data in a table.
We're halfway done with our crude operations.
We've created and read rows of data.
Now let's update our articles.js routes file to add routes for editing articles.
There's an edit form route and
There's the edit form routes and the HTTP put routes to update a given article.
Both of these routes require the article to be found first.
Let's use the findById method first in the edit form.
Once the article is found, it is passed into our form here and
in our puts update URL handler,
let's first find the article and then update the article.
Once the update has happened, then we can redirect to the individual article page.
What's happening here is that the update method is returning a promise.
Returning a promise passes the next value down the then chain.
In other words, the article here is the updated article.
Let's restart the web server
And edit our second article's text.
And update it.
And it works.
In the next video, we'll take a look at deleting entries.
You need to sign up for Treehouse in order to download course files.Sign up