1 00:00:00,960 --> 00:00:04,750 We'll end our tour of the rails console with the delete operations. 2 00:00:04,750 --> 00:00:07,660 Your users need to be able to delete data as well so 3 00:00:07,660 --> 00:00:11,050 rails also allows the removal of records from the database. 4 00:00:11,050 --> 00:00:14,440 We just load up a particular instance of the model as before and 5 00:00:14,440 --> 00:00:17,210 then call the destroy-method on it. 6 00:00:17,210 --> 00:00:19,450 Let's get a list of all the post objects again. 7 00:00:22,070 --> 00:00:28,620 And let's load a particular instance using its ID and assign it to a variable. 8 00:00:28,620 --> 00:00:34,199 Post equals post.find (4). 9 00:00:34,199 --> 00:00:37,890 Now we'll call the destroy method on that object, 10 00:00:37,890 --> 00:00:42,190 post, lower case because it's a variable named destroy. 11 00:00:44,940 --> 00:00:48,360 We'll see an SQL query that deletes the record from the database. 12 00:00:49,520 --> 00:00:52,300 Note that the method name is destroy not delete. 13 00:00:52,300 --> 00:00:53,980 A method called delete exists, but 14 00:00:53,980 --> 00:00:57,220 it works in different and potentially confusing ways. 15 00:00:57,220 --> 00:01:00,180 You'll want the destroy method in most cases. 16 00:01:00,180 --> 00:01:01,680 If we call post at all again, 17 00:01:03,400 --> 00:01:07,180 we'll see that the record we destroyed is gone from the collection. 18 00:01:07,180 --> 00:01:10,300 That wraps up our two of the rails console for now. 19 00:01:10,300 --> 00:01:13,900 Before we can run bin rails generator other commands we need to exit 20 00:01:13,900 --> 00:01:15,320 the console program. 21 00:01:15,320 --> 00:01:17,670 Type exit all by itself on a line and 22 00:01:17,670 --> 00:01:20,020 press enter and you'll be back to your system prompt.