1 00:00:00,620 --> 00:00:04,040 Next, let's look at update operations in the console. 2 00:00:04,040 --> 00:00:08,220 After retrieving a model object from the database, we can modify the object and 3 00:00:08,220 --> 00:00:10,050 update the database record. 4 00:00:10,050 --> 00:00:12,980 This is much the same as working with a new model object. 5 00:00:12,980 --> 00:00:17,320 We just assign new values, the existing object's attributes and call save on it. 6 00:00:18,440 --> 00:00:21,480 Let's suppose we wanted to update a post title. 7 00:00:21,480 --> 00:00:27,500 As before, we can get a collection of all the posts objects by calling Post.all. 8 00:00:27,500 --> 00:00:31,660 We can look at the ID attribute of the one we want to modify and 9 00:00:31,660 --> 00:00:34,630 then retrieve it by passing the ID to the find method. 10 00:00:36,900 --> 00:00:42,052 We'll assign the object we get back to a variable, post = Post.find(3). 11 00:00:43,220 --> 00:00:46,830 As before we can set the attributes the same way we would on any other 12 00:00:46,830 --> 00:00:48,320 Ruby object. 13 00:00:48,320 --> 00:00:50,097 So let's change the title. 14 00:00:50,097 --> 00:00:54,051 Post.title =" I've been 15 00:00:54,051 --> 00:00:59,072 updated!" Once again, 16 00:00:59,072 --> 00:01:03,290 these changes only exist in your computer's memory, not in the database. 17 00:01:03,290 --> 00:01:06,978 We need to call the save method on the object to update its database record. 18 00:01:06,978 --> 00:01:09,820 post.save. 19 00:01:09,820 --> 00:01:13,130 We'll see an SQL query that updates the record in the database.. 20 00:01:14,290 --> 00:01:16,200 And the next time we query that database, 21 00:01:16,200 --> 00:01:18,560 we'll see the updated title instead of the old one.