From 41095dc0e38a4469e2cae355b048d0e1865deed7 Mon Sep 17 00:00:00 2001 From: Simon Quigley Date: Tue, 26 Sep 2023 11:55:20 -0500 Subject: [PATCH] Complete Lesson 20 --- app/controllers/movies_controller.rb | 9 +++++---- app/views/layouts/_flash.html.erb | 11 +++++++++++ app/views/layouts/application.html.erb | 2 ++ 3 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 app/views/layouts/_flash.html.erb diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index 3f11d4c..e849cd4 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -11,7 +11,7 @@ class MoviesController < ApplicationController def update @movie = Movie.find(params[:id]) if @movie.update(movie_params) - redirect_to @movie + redirect_to @movie, notice: "Movie successfully updated!" else render :edit, status: :unprocessable_entity end @@ -22,15 +22,16 @@ class MoviesController < ApplicationController def create @movie = Movie.new(movie_params) if @movie.save - redirect_to @movie + redirect_to @movie, notice: "Movie successfully created!" else render :new, status: :unprocessable_entity end end def destroy @movie = Movie.find(params[:id]) - @movie.destroy - redirect_to movies_url, status: :see_other + if @movie.destroy + redirect_to movies_url, status: :see_other, alert: "Movie successfully destroyed!" + end end private diff --git a/app/views/layouts/_flash.html.erb b/app/views/layouts/_flash.html.erb new file mode 100644 index 0000000..b620a14 --- /dev/null +++ b/app/views/layouts/_flash.html.erb @@ -0,0 +1,11 @@ + <% if flash[:notice] %> +
+ <%= flash[:notice] %> +
+ <% end %> + + <% if flash[:alert] %> +
+ <%= flash[:alert] %> +
+ <% end %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 31a872a..b1251df 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -14,6 +14,8 @@ <%= render "layouts/header" %>
+ <%= render "layouts/flash" %> + <%= yield %>
<%= render "layouts/footer" %>