Created
August 11, 2012 19:02
-
-
Save fapestniegd/3326442 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb | |
index d29d5de..bf3fd7f 100644 | |
--- a/app/controllers/movies_controller.rb | |
+++ b/app/controllers/movies_controller.rb | |
@@ -7,7 +7,26 @@ class MoviesController < ApplicationController | |
end | |
def index | |
- @movies = Movie.all | |
+ sort_by = params[:sort_by] # retrieve movie ID from URI route | |
+ if defined?sort_by | |
+ if sort_by == "title" | |
+ return @movies = Movie.all.sort_by(&:title) | |
+ end | |
+ if sort_by == "release_date" | |
+ return @movies = Movie.all.sort_by(&:release_date) | |
+ | |
+ end | |
+ else | |
+ @movies = Movie.all | |
+ end | |
+ warn params.inspect | |
+ end | |
+ | |
+ def by_title | |
+ end | |
+ | |
+ def by_release_date | |
+ @movies = Movie.all.sort_by &:release_date | |
end | |
def new | |
diff --git a/app/views/movies/index.html.haml b/app/views/movies/index.html.haml | |
index 3bdc477..b2242ac 100644 | |
--- a/app/views/movies/index.html.haml | |
+++ b/app/views/movies/index.html.haml | |
@@ -4,9 +4,9 @@ | |
%table#movies | |
%thead | |
%tr | |
- %th Movie Title | |
+ %th= link_to "Movie Title", 'movies?sort_by=title' , id: 'title_header' | |
%th Rating | |
- %th Release Date | |
+ %th= link_to "Release Date", 'movies?sort_by=release_date', id: 'release_date_header' | |
%th More Info | |
%tbody | |
- @movies.each do |movie| |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment