Search⌘ K

CRUD Application: Part 3

Explore how to implement full CRUD operations in Ruby on Rails by learning to update and delete pet records. Understand editing views, creating update and destroy controller actions, and adding links for editing and removal in index and show pages.

So far, your app allows you to perform the C and R of the CRUD operations. We can look at existing pets, retrieve their details, and create new ones.

Next, you will learn how to perform the U and D on our app. Here are the steps you will follow:

  1. Edit the edit action in app/controllers/pets_controller.rb to take you to the edit view
  2. Edit edit.html.erb to display the form to edit existing pets.3. Create an update method in app/controllers/pets_controller.rb to handle form updates
  3. Edit index.html.erb and show.html.erb to display Edit links
  4. Create a destroy method to handle pet removal
  5. Edit index.html.erb and show.html.erb to display Remove links

Updating pets

Edit the edit action

You will modify your edit action in the app/controllers/pets_controller.rb file by adding the following line:

@pet = Pet.find(params[:id])

This is the same as what you did for your show action.

Edit the

...