From the course: Ruby on Rails 5 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 actions: Edit/update

Update actions: Edit/update - Ruby on Rails Tutorial

From the course: Ruby on Rails 5 Essential Training

Start my 1-month free trial

Update actions: Edit/update

- [Instructor] We've added code which will create records from our controller. Now, we want to be able to update existing records from the controller. Like create, there are two standard Rails actions for updating. Edit displays the form, while update processes the form. In fact, this two-step process of updating records is almost exactly like the process we just saw for creating them. There are only two key differences. The first is that we need to make sure that we have an ID. New and create didn't need an ID, because there was no record in the database yet, but edit and update require there be an ID so we can find that existing record. Once edit retrieves that existing record, it will use its values to pre-populate the form. Update will also need to find the object before it can update it. The second difference is going to be in the form processing. Create instantiated a new object, and then saved it. Update is going to find an existing object, and then use update attributes in…

Contents