Learn how to use models to find a record and then delete it from the database. Be careful: There is a “delete” method but “destroy” is the method name to use here.
- [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…and we call it find and destroy.…There's finding the record,…just like we when we were updating the record,…and then we destroy the record.…Now here's a gotcha that you need to be careful of.…There's also a method in Rails called delete…and it may seem to work the same as destroy does.…But delete bypasses some Rails features…and might give you unexpected behavior.…Destroy is the best method to stick with as a beginner.…
If you're still in the Rails console, that's fine,…there's no need to exit and go back in,…but I'm going to start from scratch.…And I'm going to first create a new subject.…Let's do that using Subject.create…and I'm going to give it a name…and I'm going to call it, Bad subject.…And that's going to save it to the database.…I give it an ID of three so I can find that subject…as my first step as subject, find, three.…Just clear my screen so you can see it.…
Here's the first step in the process,…
- Creating and configuring a new Ruby on Rails project
- Generating controllers and views
- Handling server requests
- Using different types of routes
- Rendering and viewing templates
- Generating migrations and models
- Creating, updating, and deleting records
- Finding records with queries
- Understanding relationship types
- Writing controllers for CRUD
- Working with layouts and helpers
- Managing application assets
- Building forms
- Validating data
- Authenticating users
Skill Level Beginner
1. What Is Ruby on Rails?
2. Get Started
3. Controllers, Views, and Dynamic Content
4. Databases and Migrations
5. Models and ActiveRecord
7. CRUD, REST, and Resourceful Routes
8. Controllers and CRUD
9. Layouts, Partials, and View Helpers
12. Data Validation
13. Controller Features
14. User Authentication
15. Improve the Simple CMS
Next steps1m 44s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.