|
|
@ -1,5 +1,7 @@
|
|
|
|
class MoviesController < ApplicationController
|
|
|
|
class MoviesController < ApplicationController
|
|
|
|
|
|
|
|
before_action :require_signin, except: [:index, :show]
|
|
|
|
before_action :require_admin, except: [:index, :show]
|
|
|
|
before_action :require_admin, except: [:index, :show]
|
|
|
|
|
|
|
|
before_action :set_movie, only: [:show, :edit, :update, :destroy]
|
|
|
|
|
|
|
|
|
|
|
|
def index
|
|
|
|
def index
|
|
|
|
case params[:filter]
|
|
|
|
case params[:filter]
|
|
|
@ -12,7 +14,6 @@ class MoviesController < ApplicationController
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def show
|
|
|
|
def show
|
|
|
|
@movie = Movie.find(params[:id])
|
|
|
|
|
|
|
|
@fans = @movie.fans
|
|
|
|
@fans = @movie.fans
|
|
|
|
@genres = @movie.genres.order(:name)
|
|
|
|
@genres = @movie.genres.order(:name)
|
|
|
|
|
|
|
|
|
|
|
@ -21,10 +22,8 @@ class MoviesController < ApplicationController
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def edit
|
|
|
|
def edit
|
|
|
|
@movie = Movie.find(params[:id])
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def update
|
|
|
|
def update
|
|
|
|
@movie = Movie.find(params[:id])
|
|
|
|
|
|
|
|
if @movie.update(movie_params)
|
|
|
|
if @movie.update(movie_params)
|
|
|
|
redirect_to @movie, notice: "Movie successfully updated!"
|
|
|
|
redirect_to @movie, notice: "Movie successfully updated!"
|
|
|
|
else
|
|
|
|
else
|
|
|
@ -43,7 +42,6 @@ class MoviesController < ApplicationController
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def destroy
|
|
|
|
def destroy
|
|
|
|
@movie = Movie.find(params[:id])
|
|
|
|
|
|
|
|
if @movie.destroy
|
|
|
|
if @movie.destroy
|
|
|
|
redirect_to movies_url, status: :see_other, alert: "Movie successfully destroyed!"
|
|
|
|
redirect_to movies_url, status: :see_other, alert: "Movie successfully destroyed!"
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -51,6 +49,10 @@ class MoviesController < ApplicationController
|
|
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def set_movie
|
|
|
|
|
|
|
|
@movie = Movie.find_by!(slug: params[:id])
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def movie_params
|
|
|
|
def movie_params
|
|
|
|
params.require(:movie).permit(:title, :description, :rating, :released_on, :total_gross, :director, :duration, :image_file_name, genre_ids: [])
|
|
|
|
params.require(:movie).permit(:title, :description, :rating, :released_on, :total_gross, :director, :duration, :image_file_name, genre_ids: [])
|
|
|
|
end
|
|
|
|
end
|
|
|
|