Skip to content

Commit

Permalink
Added rest of solution, for parts 4 and 5.
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Xia committed Feb 7, 2012
1 parent 0aa5a94 commit b34151c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
16 changes: 12 additions & 4 deletions app/controllers/movies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,22 @@ def show
end

def index
if params[:title_sort]
sort = params[:sort] || session[:sort]
case sort
when 'title'
ordering,@title_header = {:order => :title}, 'hilite'
elsif params[:release_date_sort]
when 'release_date'
ordering,@date_header = {:order => :release_date}, 'hilite'
end
@all_ratings = Movie.all_ratings
@selected_ratings = (params[:ratings] ||= {}).keys
@movies = Movie.find_all_by_rating(@selected_ratings, ordering)
@selected_ratings = params[:ratings] || session[:ratings] || {}

if params[:sort] != session[:sort] or params[:ratings] != session[:ratings]
session[:sort] = sort
session[:ratings] = @selected_ratings
redirect_to :sort => sort, :ratings => @selected_ratings and return
end
@movies = Movie.find_all_by_rating(@selected_ratings.keys, ordering)
end

def new
Expand Down
10 changes: 6 additions & 4 deletions app/views/movies/index.html.haml
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
-# This file is app/views/movies/index.html.haml
%h1 All Movies

= form_tag movies_path, :method => :get do
= form_tag movies_path, :method => :get, :id => 'ratings_form' do
= hidden_field_tag "title_sort", true if @title_header
= hidden_field_tag ":release_date_sort", true if @date_header
Include:
- @all_ratings.each do |rating|
= rating
= check_box_tag "ratings[#{rating}]", 1, @selected_ratings.include?(rating)
= submit_tag 'Refresh'
= submit_tag 'Refresh', :id => 'ratings_submit'

%table#movies
%thead
%tr
%th{:class => @title_header}= link_to 'Movie Title', movies_path(:title_sort => true)
%th{:class => @title_header}= link_to 'Movie Title', movies_path(:sort => 'title', :ratings => @selected_ratings), :id => 'title_header'
%th Rating
%th{:class=>@date_header}= link_to 'Release Date', movies_path(:release_date_sort => true)
%th{:class => @date_header}= link_to 'Release Date', movies_path(:sort => 'release_date', :ratings => @selected_ratings), :id => 'release_date_header'
%th More Info
%tbody
- @movies.each do |movie|
Expand Down
Binary file modified db/development.sqlite3
Binary file not shown.

0 comments on commit b34151c

Please sign in to comment.