Permalink
Browse files

The filtering is now kept when ordering

  • Loading branch information...
1 parent fd8010f commit 4d0fb0fcc0d3728edbdb0db656cfb5c7ee8ea13a Einar Jonsson committed Mar 9, 2012
Showing with 12 additions and 6 deletions.
  1. +11 −5 app/controllers/movies_controller.rb
  2. +1 −1 app/views/movies/index.html.haml
@@ -9,22 +9,28 @@ def show
def index
@all_ratings = Movie.all_ratings
- ratings_filter = params[:ratings].keys unless params[:ratings].nil?
- @ratings = params[:ratings] ? params[:ratings] : []
+
+ if params[:ratings]
+ ratings_filter = params[:ratings].keys
+ session[:ratings_filter] = ratings_filter
+ end
+ @ratings = session[:ratings_filter] ? session[:ratings_filter] : []
@movies = Movie.all(:conditions => [
"rating IN (:ratings)", {
- :ratings => ratings_filter ? ratings_filter : @all_ratings
+ :ratings => @ratings ? @ratings : @all_ratings
}
- ])
+ ],
+ :order => params[:sort_by]
+ )
+ # Highlight the sort column
if params[:sort_by]
if params[:sort_by] == 'title'
@title_class = 'hilite'
elsif params[:sort_by] == 'release_date'
@release_date_class = 'hilite'
end
- @movies = @movies.order(params[:sort_by])
end
end
@@ -6,7 +6,7 @@
- @all_ratings.each do |rating|
= rating
= check_box_tag "ratings[#{rating}]", '1', @ratings.include?(rating)
- = submit_tag 'Refresh'
+ = submit_tag 'Refresh', :id => "ratings_submit"
%table#movies
%thead

0 comments on commit 4d0fb0f

Please sign in to comment.