They both update records… But not the same way 👇

🚨 Quick Breakdown

  • PUT = Full update
  • PATCH = Partial update

🧠 In Rails terms…

Action Request Type Behavior
update (full) PUT Replaces the entire record
update (partial) PATCH Changes only specific attributes

🔧 Example

PUT /products/1
{
  "name": "New Name",
  "price": 99,
  "category": "Books"
}
# All attributes must be sent!

PATCH /products/1
{
  "price": 99
}
# Just updates one field 🧼

🧪 What Rails Does

  • Both hit the update method in your controller:
def update
  if @product.update(product_params)
    redirect_to @product
  else
    render :edit
  end
end
  • But the HTTP verb tells the intent:
    • PUT = Replace all
    • PATCH = Update parts

🎯 When to Use

  • Use PUT if you want to overwrite the whole object
  • Use PATCH for lightweight updates

🧵 TL;DR

  • PUT: Full update – replaces the whole record ✅
  • PATCH: Partial update – tweaks only what you send ✂️
  • Both go through the same controller method in Rails (update)
  • Pick the right verb for the right job 💪