From the course: Ruby on Rails 6 Essential Training
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Delete records using ActiveRecord - Ruby on Rails Tutorial
From the course: Ruby on Rails 6 Essential Training
Delete records using ActiveRecord
[Instructor]- We've seen how to create and update records. Now let's learn how to delete them. Deleting records is a two-step process, find and destroy. First you find the record in the database table. Rails uses the data that it gets back to populate, and return an instance of the class. And then you tell that object that it should destroy itself. There's only one pitfall that you need to be careful of. We're talking about deleting records. But the method we're going to be using is called destroy. Destroy, Will create an SQL delete statement. There's also another method in rails called delete. It also sends an SQL delete statement. These two methods may seem to work the same way, but delete bypasses some rails features, and might give you unexpected behavior. Most of the time, the best method to use is destroy. If you're still in the rails console from the last preview, that's fine, there's no need to exit, but I'm going to…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
(Locked)
Understanding ActiveRecord and ActiveRelation4m 32s
-
(Locked)
Using the Rails console to interact with a Rails project3m 36s
-
Create records using ActiveRecord5m 11s
-
(Locked)
Update records using ActiveRecord3m 53s
-
(Locked)
Delete records using ActiveRecord3m 18s
-
(Locked)
Find records using ActiveRecord6m 33s
-
(Locked)
Define one-to-many associations between models6m 30s
-
(Locked)
-
-
-