From the course: Ruby on Rails 5 Essential Training

Unlock the full course today

Join today to access over 22,700 courses taught by industry experts or purchase this course individually.

Update records

Update records - Ruby on Rails Tutorial

From the course: Ruby on Rails 5 Essential Training

Start my 1-month free trial

Update records

- [Instructor] In the last movie, we learned to create records using Active Record. In this movie, we're going to learn to update those records. Like creating records, there are two techniques that we can use for updating. One, is where you set the attributes one at a time, and then save. And one, where you set the attributes and save it all at once. Let's first look at the technique I'll call find save. First, you find a record, then you set its values, and then you save it. It's very similar to what we had with new save. The other technique, is using find and update attributes. We still have to find the record, but then, we can 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'm gonna launch my console again, and the first step is going to be to find the record that we want. I'm going to use subject equals subject dot find one. This…

Contents