From 2b32bc0e621a8c3b9cb946fd4b202ccf9bf4eefd Mon Sep 17 00:00:00 2001 From: Simon Quigley Date: Mon, 25 Sep 2023 15:28:26 -0500 Subject: [PATCH] Complete Lesson 12 Part 2 --- app/controllers/movies_controller.rb | 6 ++++++ config/routes.rb | 1 + 2 files changed, 7 insertions(+) diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index 3308601..d8ce621 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -11,4 +11,10 @@ class MoviesController < ApplicationController def edit @movie = Movie.find(params[:id]) end + def update + @movie = Movie.find(params[:id]) + movie_params = params.require(:movie).permit(:title, :description, :rating, :released_on, :total_gross) + @movie.update(movie_params) + redirect_to @movie + end end diff --git a/config/routes.rb b/config/routes.rb index 68b3d10..210108c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,5 +2,6 @@ Rails.application.routes.draw do root "movies#index" get "movies" => "movies#index" get "movies/:id" => "movies#show", as: "movie" + patch "movies/:id" => "movies#update" get "movies/:id/edit" => "movies#edit", as: "edit_movie" end