From b6237c5daae2e0e8c1cb8991e1ec732b52de4340 Mon Sep 17 00:00:00 2001 From: Simon Quigley Date: Mon, 25 Sep 2023 15:22:01 -0500 Subject: [PATCH] Complete Lesson 12 Part 1 --- app/controllers/movies_controller.rb | 3 +++ app/views/movies/edit.html.erb | 20 ++++++++++++++++++++ app/views/movies/show.html.erb | 3 +++ config/routes.rb | 1 + 4 files changed, 27 insertions(+) create mode 100644 app/views/movies/edit.html.erb diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index 915dc61..3308601 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -8,4 +8,7 @@ class MoviesController < ApplicationController def show @movie = Movie.find(params[:id]) end + def edit + @movie = Movie.find(params[:id]) + end end diff --git a/app/views/movies/edit.html.erb b/app/views/movies/edit.html.erb new file mode 100644 index 0000000..0d4325e --- /dev/null +++ b/app/views/movies/edit.html.erb @@ -0,0 +1,20 @@ +

Editing <%= @movie.title %>

+ +<%= form_with(model: @movie) do |f| %> + <%= f.label :title %> + <%= f.text_field :title %> + + <%= f.label :description %> + <%= f.text_area :description, rows: 7 %> + + <%= f.label :rating %> + <%= f.text_field :rating %> + + <%= f.label :released_on %> + <%= f.date_field :released_on %> + + <%= f.label :total_gross %> + <%= f.number_field :total_gross %> + + <%= f.submit %> +<% end %> diff --git a/app/views/movies/show.html.erb b/app/views/movies/show.html.erb index 2bd7a2d..2e34224 100644 --- a/app/views/movies/show.html.erb +++ b/app/views/movies/show.html.erb @@ -13,5 +13,8 @@ <%= total_gross(@movie) %> +
+ <%= link_to "Edit", edit_movie_path(@movie), class: "button" %> +
diff --git a/config/routes.rb b/config/routes.rb index f91c3ee..68b3d10 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,4 +2,5 @@ Rails.application.routes.draw do root "movies#index" get "movies" => "movies#index" get "movies/:id" => "movies#show", as: "movie" + get "movies/:id/edit" => "movies#edit", as: "edit_movie" end