Skip to content

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.
...
  • 3 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
View
3 app/assets/stylesheets/application.css
@@ -48,6 +48,9 @@ table#movies th, table#movies td {
padding: 4px;
text-align: left;
}
+table#movies th.hilite {
+ background-color: yellow;
+}
#notice #warning {
background: rosybrown;
margin: 1em 0;
View
18 app/controllers/movies_controller.rb
@@ -7,7 +7,23 @@ def show
end
def index
- @movies = Movie.all
+ sort_by = params[:sort]
+ if params.has_key?(:ratings)
+ ratings = params[:ratings].keys
+ else
+ ratings = []
+ end
+ params.has_key?(:ratings) ? @ratings_selected = params[:ratings].keys : @ratings_selected = []
+ @all_ratings = Movie.possible_ratings
+ puts "Here are ratings: #{ratings}"
+ #@all_ratings = ['G','PG','PG-13','R']
+ if sort_by == "sortByTitle"
+ @movies = Movie.find(:all, :order => 'title ASC', :conditions => [ "rating IN (?)", ratings])
+ elsif sort_by == "sortByDate"
+ @movies = Movie.find(:all, :order => 'release_date ASC', :conditions => [ "rating IN (?)", ratings])
+ else
+ @movies = Movie.find(:all, :conditions => [ "rating IN (?)", ratings])
+ end
end
def new
View
3 app/models/movie.rb
@@ -1,2 +1,5 @@
class Movie < ActiveRecord::Base
+ def self.possible_ratings
+ self.select(:rating).map(&:rating).uniq.sort
+ end
end
View
17 app/views/movies/index.html.haml
@@ -1,12 +1,21 @@
-# This file is app/views/movies/index.html.haml
%h1 All Movies
-
+= puts "Params: #{params}"
+= form_tag movies_path, :method => :get do
+ Include:
+ - @all_ratings.each do |rating|
+ = rating
+ - if (@ratings_selected.include?(rating))
+ = check_box_tag "ratings[#{rating}]", 1, true, :id => "ratings_#{rating}"
+ - else
+ = check_box_tag "ratings[#{rating}]", 1, false, :id => "ratings_#{rating}"
+ = submit_tag 'Refresh', :id => "ratings_submit"
%table#movies
%thead
%tr
- %th Movie Title
+ %th{:class => (params[:sort] == "sortByTitle" ? 'hilite' : nil)}= link_to "Movie Title", movies_path({:sort => "sortByTitle", :ratings => params[:ratings]}), :id => "title_header"
%th Rating
- %th Release Date
+ %th{:class => (params[:sort] == "sortByDate" ? 'hilite' : nil)}= link_to "Release Date", movies_path(:sort => "sortByDate",:ratings => params[:ratings]), :id => "release_date_header"
%th More Info
%tbody
- @movies.each do |movie|
@@ -16,4 +25,4 @@
%td= movie.release_date
%td= link_to "More about #{movie.title}", movie_path(movie)
-= link_to 'Add new movie', new_movie_path
+= link_to 'Add new movie', new_movie_path

No commit comments for this range

Something went wrong with that request. Please try again.