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.

Update records using ActiveRecord

Update records using ActiveRecord - Ruby on Rails Tutorial

From the course: Ruby on Rails 6 Essential Training

Start my 1-month free trial

Update records using ActiveRecord

- [Instructor] In the last movie, we used our models to create records in the database. In this movie, we will learn to update those records. Like creating records, there're two techniques we can use for updating. The first I call the find and save technique. First, you find a record, then you set its values and then you save it. It's very similar to what we were doing when we were working with new before. We're finding the records so that we have an instance to work with, we set the values and then we save it. The second technique is what we would call find and update. We still have to find the record but then we set the values and save all in one step so it's a two-step process. Let's try them both. If you're still in the console after the last movie, that's fine, there's no need to exit and go back in. But I will launch my Rails console again. The first step is to find the record that we want. So we'll have subject…

Contents