1 class MoviesController < ApplicationController
4 id = params[:id] # retrieve movie ID from URI route
5 @movie = Movie.find(id) # look up movie by unique ID
6 # will render app/views/movies/show.<extension> by default
10 #logger.info params.inspect
12 if !params[:ratings] && !params['sort-by'] && !params['commit'] && session['index-params']
13 ss = session['index-params']
14 session['index-params'] = nil
15 return redirect_to movies_path(ss)
18 session['index-params'] = {
19 :ratings => params[:ratings],
20 'sort-by' => params['sort-by']
25 @ratings = params[:ratings]
30 params[:ratings].each_key { |k| @filters[k] = true }
31 find_params[:conditions] = { :rating => params[:ratings].keys }
34 case params['sort-by']
37 find_params[:order] = 'title'
39 @hilite_release_date = true
40 find_params[:order] = 'release_date'
43 @movies = Movie.all(find_params)
45 @all_ratings = Movie.select(:rating).map { |x| x.rating }.uniq # TODO: issue SELECT DISTINCT
50 # default: render 'new' template
54 @movie = Movie.create!(params[:movie])
55 flash[:notice] = "#{@movie.title} was successfully created."
56 redirect_to movies_path
60 @movie = Movie.find params[:id]
64 @movie = Movie.find params[:id]
65 @movie.update_attributes!(params[:movie])
66 flash[:notice] = "#{@movie.title} was successfully updated."
67 redirect_to movie_path(@movie)
71 @movie = Movie.find(params[:id])
73 flash[:notice] = "Movie '#{@movie.title}' deleted."
74 redirect_to movies_path