parent
2e4e522c96
commit
c3fbb70cff
@ -1,42 +1,42 @@
|
|||||||
class MoviesController < ApplicationController
|
class MoviesController < ApplicationController
|
||||||
def index
|
def index
|
||||||
@movies = Movie.released
|
@movies = Movie.released
|
||||||
end
|
end
|
||||||
def show
|
def show
|
||||||
@movie = Movie.find(params[:id])
|
@movie = Movie.find(params[:id])
|
||||||
end
|
end
|
||||||
def edit
|
def edit
|
||||||
@movie = Movie.find(params[:id])
|
@movie = Movie.find(params[:id])
|
||||||
end
|
end
|
||||||
def update
|
def update
|
||||||
@movie = Movie.find(params[:id])
|
@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
|
||||||
render :edit, status: :unprocessable_entity
|
render :edit, status: :unprocessable_entity
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
def new
|
def new
|
||||||
@movie = Movie.new
|
@movie = Movie.new
|
||||||
end
|
end
|
||||||
def create
|
def create
|
||||||
@movie = Movie.new(movie_params)
|
@movie = Movie.new(movie_params)
|
||||||
if @movie.save
|
if @movie.save
|
||||||
redirect_to @movie, notice: "Movie successfully created!"
|
redirect_to @movie, notice: "Movie successfully created!"
|
||||||
else
|
else
|
||||||
render :new, status: :unprocessable_entity
|
render :new, status: :unprocessable_entity
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
def destroy
|
def destroy
|
||||||
@movie = Movie.find(params[:id])
|
@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
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def movie_params
|
def movie_params
|
||||||
params.require(:movie).permit(:title, :description, :rating, :released_on, :total_gross, :director, :duration, :image_file_name)
|
params.require(:movie).permit(:title, :description, :rating, :released_on, :total_gross, :director, :duration, :image_file_name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,2 +1,9 @@
|
|||||||
module ReviewsHelper
|
module ReviewsHelper
|
||||||
|
def average_stars(movie)
|
||||||
|
if movie.average_stars.zero?
|
||||||
|
content_tag(:strong, "No reviews")
|
||||||
|
else
|
||||||
|
pluralize(number_with_precision(movie.average_stars, precision: 1) , "star")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in new issue