daily pastebin goal
20%
SHARE
TWEET

Untitled

a guest Mar 22nd, 2018 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class MoviesController < ApplicationController
  2.  
  3.   def movie_params
  4.     params.require(:movie).permit(:title, :rating, :description, :release_date)
  5.   end
  6.  
  7.   def show
  8.     id = params[:id] # retrieve movie ID from URI route
  9.     @movie = Movie.find(id) # look up movie by unique ID
  10.     # will render app/views/movies/show.<extension> by default
  11.   end
  12.  
  13.   def index
  14.     @all_ratings = ['G','PG','PG-13','R']
  15.     @checkbox_values = {}
  16.     @valid_ratings = @all_ratings
  17.    
  18.     if (params["ratings"] == nil)
  19.       @all_ratings.each do |movie_rating|
  20.         @checkbox_values[movie_rating] = true;
  21.       end
  22.     else
  23.       @valid_ratings = []
  24.       params["ratings"].each_key do |key|
  25.         @checkbox_values[key] = true;
  26.         @valid_ratings << key
  27.       end
  28.     end
  29.    
  30.     @hilite = {}
  31.     @hilite[:title] = ''
  32.     @hilite[:release_date] = ''
  33.    
  34.     if params[:sort] == nil
  35.       @movies = Movie.where(rating: @valid_ratings)
  36.     else
  37.       order = params[:sort] + ' ASC'
  38.       @hilite[params[:sort].to_sym] = 'hilite'
  39.       @movies = Movie.order(order).all
  40.     end
  41.   end
  42.  
  43.   def new
  44.     # default: render 'new' template
  45.   end
  46.  
  47.   def create
  48.     @movie = Movie.create!(movie_params)
  49.     flash[:notice] = "#{@movie.title} was successfully created."
  50.     redirect_to movies_path
  51.   end
  52.  
  53.   def edit
  54.     @movie = Movie.find params[:id]
  55.   end
  56.  
  57.   def update
  58.     @movie = Movie.find params[:id]
  59.     @movie.update_attributes!(movie_params)
  60.     flash[:notice] = "#{@movie.title} was successfully updated."
  61.     redirect_to movie_path(@movie)
  62.   end
  63.  
  64.   def destroy
  65.     @movie = Movie.find(params[:id])
  66.     @movie.destroy
  67.     flash[:notice] = "Movie '#{@movie.title}' deleted."
  68.     redirect_to movies_path
  69.   end
  70.  
  71. end
RAW Paste Data
Top