Permalink
Browse files

new hw

  • Loading branch information...
jaesgar committed Mar 9, 2012
1 parent 92a392d commit 33e1be85bceb2dbbbdbf213dea8f3de9ac6993a3
@@ -59,3 +59,7 @@ form label {
font-weight: bold;
color: maroon;
}
+table#movies th.hilite {
+ background-color: yellow;
+}
+
@@ -7,7 +7,13 @@ def show
end
def index
- @movies = Movie.all
+ @sort_val = ["title","release_date"].include?(params[:sort_by])?params[:sort_by] : nil;
+ @ratings_val = (params[:ratings] != nil)? params[:ratings]: Hash.new;
+ condition = (@ratings_val.keys.empty? == false)?["rating IN (?)", @ratings_val.keys] : nil;
+ @movies = Movie.find(:all, :conditions => condition, :order => @sort_val)
+ @all_ratings = Movie.all_ratings
+ # @all_ratings.each{|rating| logger.info(rating.rating)}
+ # logger.info(@all_ratings)
end
def new
@@ -37,5 +43,6 @@ def destroy
flash[:notice] = "Movie '#{@movie.title}' deleted."
redirect_to movies_path
end
+
end
View
@@ -1,2 +1,11 @@
class Movie < ActiveRecord::Base
+
+def self.all_ratings
+ ratings = Array.new
+ Movie.find(:all, :select => "DISTINCT rating", :order => 'rating').each {|rating|
+ ratings<<rating.rating;
+ }
+ ratings
end
+
+end
@@ -1,12 +1,20 @@
-# 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
+ = check_box_tag "ratings[#{rating}]", 1 ,(@ratings_val.key?(rating) && @ratings_val[rating])
+ = hidden_field_tag :sort_by, @sort_val
+ = submit_tag 'Refresh', :id=>"ratings_submit"
+
%table#movies
%thead
%tr
- %th Movie Title
+ %th#title_header{:class=> @sort_val=='title' && 'hilite'}= link_to "Movie Title", {:controller=>"movies", :ratings => @ratings_val, :sort_by=>"title"}
%th Rating
- %th Release Date
+ %th#release_date_header{:class=> @sort_val=='release_date' && 'hilite'}= link_to "Release Date", {:controller=>"movies", :ratings => @ratings_val, :sort_by=>"release_date"}
%th More Info
%tbody
- @movies.each do |movie|

0 comments on commit 33e1be8

Please sign in to comment.