Skip to content

Commit

Permalink
new branch for hw2 solution
Browse files Browse the repository at this point in the history
  • Loading branch information
armandofox committed Jan 30, 2012
1 parent fcad7c2 commit a97d021
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 4 deletions.
3 changes: 3 additions & 0 deletions app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 8 additions & 1 deletion app/controllers/movies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ def show
end

def index
@movies = Movie.all
if params[:title_sort]
ordering,@title_header = {:order => :title}, 'hilite'
elsif params[:release_date_sort]
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)
end

def new
Expand Down
3 changes: 3 additions & 0 deletions app/models/movie.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
class Movie < ActiveRecord::Base
def self.all_ratings
%w(G PG PG-13 NC-17 R)
end
end
11 changes: 9 additions & 2 deletions app/views/movies/index.html.haml
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
-# 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, @selected_ratings.include?(rating)
= submit_tag 'Refresh'

%table#movies
%thead
%tr
%th Movie Title
%th{:class => @title_header}= link_to 'Movie Title', movies_path(:title_sort => true)
%th Rating
%th Release Date
%th{:class=>@date_header}= link_to 'Release Date', movies_path(:release_date_sort => true)
%th More Info
%tbody
- @movies.each do |movie|
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# Sample resource route (maps HTTP verbs to controller actions automatically):
# resources :products
resources :movies

# Sample resource route with options:
# resources :products do
# member do
Expand Down
Binary file modified db/development.sqlite3
Binary file not shown.

0 comments on commit a97d021

Please sign in to comment.