Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MoviesController < ApplicationController
- def movie_params
- params.require(:movie).permit(:title, :rating, :description, :release_date)
- end
- def show
- id = params[:id] # retrieve movie ID from URI route
- @movie = Movie.find(id) # look up movie by unique ID
- # will render app/views/movies/show.<extension> by default
- end
- def index
- @all_ratings = ['G','PG','PG-13','R']
- @checkbox_values = {}
- @valid_ratings = @all_ratings
- if (params["ratings"] == nil)
- @all_ratings.each do |movie_rating|
- @checkbox_values[movie_rating] = true;
- end
- else
- @valid_ratings = []
- params["ratings"].each_key do |key|
- @checkbox_values[key] = true;
- @valid_ratings << key
- end
- end
- @hilite = {}
- @hilite[:title] = ''
- @hilite[:release_date] = ''
- if params[:sort] == nil
- @movies = Movie.where(rating: @valid_ratings)
- else
- order = params[:sort] + ' ASC'
- @hilite[params[:sort].to_sym] = 'hilite'
- @movies = Movie.order(order).all
- end
- end
- def new
- # default: render 'new' template
- end
- def create
- @movie = Movie.create!(movie_params)
- flash[:notice] = "#{@movie.title} was successfully created."
- redirect_to movies_path
- end
- def edit
- @movie = Movie.find params[:id]
- end
- def update
- @movie = Movie.find params[:id]
- @movie.update_attributes!(movie_params)
- flash[:notice] = "#{@movie.title} was successfully updated."
- redirect_to movie_path(@movie)
- end
- def destroy
- @movie = Movie.find(params[:id])
- @movie.destroy
- flash[:notice] = "Movie '#{@movie.title}' deleted."
- redirect_to movies_path
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement