Created
March 29, 2012 13:48
-
-
Save asunar/2237638 to your computer and use it in GitHub Desktop.
movies_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MoviesController < ApplicationController | |
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 | |
redirect =false | |
#debugger | |
if params[:sort_by].nil? and !(session[:sort_by].nil?) | |
params[:sort_by] = session[:sort_by] | |
redirect = true | |
else | |
session[:sort_by] = params[:sort_by] | |
end | |
if (params[:ratings].nil? and params[:commit].nil?) and !(session[:ratings].nil?) | |
params[:ratings] = session[:ratings] | |
redirect = true | |
else | |
session[:ratings] = params[:ratings] | |
end | |
#debugger | |
redirect_to movies_path params if redirect | |
@sort_by = params[:sort_by] | |
@all_ratings = Movie.get_unique_ratings | |
selected_ratings_hash ||= params[:ratings] ||= {} | |
@selected_ratings = selected_ratings_hash.keys | |
@rating_params = @selected_ratings.map { |x| "ratings[#{x}]=1"}.join("&") | |
if selected_ratings_hash.empty? | |
@movies = Movie.all(:order => @sort_by) | |
else | |
@movies = Movie.find_all_by_rating(@selected_ratings, :order => @sort_by) | |
end | |
end | |
#snip | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment