Permalink
Browse files

HW2 Part 1

  • Loading branch information...
1 parent d71fcaf commit a1dfcee2141d1a4fd24fd615f7efd918a3c3cdce @chinpira committed Aug 14, 2012
@@ -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;
@@ -7,7 +7,14 @@ def show
end
def index
- @movies = Movie.all
+ sort_by = params[:sort]
+ if sort_by == "sortByTitle"
+ @movies = Movie.find(:all, :order => 'title ASC')
+ elsif sort_by == "sortByDate"
+ @movies = Movie.find(:all, :order => 'release_date ASC')
+ else
+ @movies = Movie.all
+ end
end
def new
@@ -4,9 +4,9 @@
%table#movies
%thead
%tr
- %th Movie Title
+ %th#title_header{:class => (params[:sort] == "sortByTitle" ? 'hilite' : nil)}= link_to "Movie Title", movies_path(:sort => "sortByTitle")
%th Rating
- %th Release Date
+ %th#release_date_header{:class => (params[:sort] == "sortByDate" ? 'hilite' : nil)}= link_to "Release Date", movies_path(:sort => "sortByDate")
%th More Info
%tbody
- @movies.each do |movie|
@@ -16,4 +16,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

0 comments on commit a1dfcee

Please sign in to comment.