Complete Lesson 20

This commit is contained in:
Simon Quigley 2023-09-26 11:55:20 -05:00
parent 1656289d7d
commit 41095dc0e3
3 changed files with 18 additions and 4 deletions

View File

@ -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

View File

@ -0,0 +1,11 @@
<% if flash[:notice] %>
<div class="flash notice">
<%= flash[:notice] %>
</div>
<% end %>
<% if flash[:alert] %>
<div class="flash alert">
<%= flash[:alert] %>
</div>
<% end %>

View File

@ -14,6 +14,8 @@
<body>
<%= render "layouts/header" %>
<div class="content">
<%= render "layouts/flash" %>
<%= yield %>
</div>
<%= render "layouts/footer" %>