Update Products
Explore how to create an update action for user-owned products in a Rails API. Understand fetching, updating, and securing products with before_action filters. Learn to write tests ensuring only authorized users can update their products and configure routes for PUT and PATCH requests.
We'll cover the following...
We'll cover the following...
Hopefully, by now the logic to build the upcoming actions is clear. This lesson will focus on the update action for when we need to fetch the product from the database and update it.
Define update action
We will implement the update action on the users controller in app/controllers/api/v1/products_controller.rb. The code for the update function is below.
The implementation is quite simple. We will retrieve the product from the ...