Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: mck-/hw2_rottenpotatoes
base: 2ff1e2cd68
...
head fork: mck-/hw2_rottenpotatoes
compare: e4d64cadbc
Checking mergeability… Don't worry, you can still create the pull request.
  • 18 commits
  • 6 files changed
  • 0 commit comments
  • 1 contributor
View
1  Gemfile
@@ -9,6 +9,7 @@ gem 'rails', '3.1.0'
group :development, :test do
gem 'sqlite3'
gem 'ruby-debug19', :require => 'ruby-debug'
+ gem 'ruby-debug-base19', " ~> 0.11.26"
end
group :production do
gem 'pg'
View
7 Gemfile.lock
@@ -41,7 +41,7 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.2.0)
- columnize (0.3.5)
+ columnize (0.3.6)
erubis (2.7.0)
execjs (1.2.13)
multi_json (~> 1.0)
@@ -53,7 +53,7 @@ GEM
thor (~> 0.14)
json (1.6.3)
libv8 (3.3.10.4)
- linecache19 (0.5.12)
+ linecache19 (0.5.13)
ruby_core_source (>= 0.1.4)
mail (2.3.0)
i18n (>= 0.4.0)
@@ -90,7 +90,7 @@ GEM
rake (0.9.2.2)
rdoc (3.12)
json (~> 1.4)
- ruby-debug-base19 (0.11.25)
+ ruby-debug-base19 (0.11.26)
columnize (>= 0.3.1)
linecache19 (>= 0.5.11)
ruby_core_source (>= 0.1.4)
@@ -132,6 +132,7 @@ DEPENDENCIES
jquery-rails
pg
rails (= 3.1.0)
+ ruby-debug-base19 (~> 0.11.26)
ruby-debug19
sass-rails (~> 3.1.0)
sqlite3
View
3  app/assets/stylesheets/application.css
@@ -59,3 +59,6 @@ form label {
font-weight: bold;
color: maroon;
}
+table#movies th.hilite {
+ background-color: yellow;
+}
View
24 app/controllers/movies_controller.rb
@@ -7,7 +7,29 @@ def show
end
def index
- @movies = Movie.all
+# raise session.inspect
+ @all_ratings = Movie.get_ratings
+
+ if !params[:ratings] && session[:ratings]
+ redirect_to(movies_path({:ratings => session[:ratings], :sort => params[:sort]}))
+ elsif !params[:sort] && session[:sort]
+ redirect_to(movies_path({:ratings => params[:ratings], :sort => session[:sort]}))
+ else
+ @checked_ratings = params[:ratings]
+ session[:ratings] = @checked_ratings
+ session[:sort] = params[:sort]
+ if @checked_ratings
+ @movies = Movie.where(:rating => @checked_ratings.keys)
+ else
+ @movies = Movie.all
+ end
+ end
+
+ if params[:sort] == "title"
+ @movies = @movies.sort_by {|m| m.title}
+ elsif params[:sort] == "date"
+ @movies = @movies.sort_by {|m| m.release_date}
+ end
end
def new
View
3  app/models/movie.rb
@@ -1,2 +1,5 @@
class Movie < ActiveRecord::Base
+ def self.get_ratings
+ Movie.all.collect{|x| x.rating}.uniq
+ end
end
View
21 app/views/movies/index.html.haml
@@ -1,12 +1,29 @@
-# This file is app/views/movies/index.html.haml
%h1 All Movies
+= form_tag movies_path, :method => :get do
+ Include:
+ - @all_ratings.each do |rating|
+ = rating
+ - if @checked_ratings && @checked_ratings.keys.member?(rating)
+ = check_box_tag "ratings[#{rating}]",1, true
+ - else
+ = check_box_tag "ratings[#{rating}]"
+ = submit_tag('Refresh', :id => 'ratings_submit')
+
%table#movies
%thead
%tr
- %th Movie Title
+ - if params[:sort] == 'title'
+ %th.hilite= link_to("Movie Title", movies_path({:sort => :title, :ratings => @checked_ratings}), :id => 'title_header')
+ - else
+ %th= link_to("Movie Title", movies_path({:sort => :title, :ratings => @checked_ratings}), :id => 'title_header')
%th Rating
- %th Release Date
+ - if params[:sort] == 'date'
+ %th.hilite= link_to("Release Date", movies_path({:sort => :date, :ratings => @checked_ratings}), :id => 'release_date_header')
+ - else
+ %th= link_to("Release Date", movies_path({:sort => :date, :ratings => @checked_ratings}), :id => 'release_date_header')
+
%th More Info
%tbody
- @movies.each do |movie|

No commit comments for this range

Something went wrong with that request. Please try again.