Permalink
Browse files

session pars for sort and filter with restful redirect

  • Loading branch information...
1 parent 3846045 commit 92bf2ed5e6ffd410a30a3a87d9610475393ad663 @mck- committed Mar 9, 2012
Showing with 7 additions and 9 deletions.
  1. +7 −9 app/controllers/movies_controller.rb
@@ -10,24 +10,22 @@ def index
# raise session.inspect
@all_ratings = Movie.get_ratings
- if params[:ratings]
+ if !params[:ratings]
+ redirect_to(movies_path({:ratings => session[:ratings], :sort => params[:sort]}))
+ elsif !params[:sort]
+ redirect_to(movies_path({:ratings => params[:ratings], :sort => session[:sort]}))
+ else
@checked_ratings = params[:ratings]
session[:ratings] = @checked_ratings
+ session[:sort] = params[:sort]
@movies = Movie.where(:rating => params[:ratings].keys)
- else
- if session[:ratings]
- redirect_to(movies_path({:ratings => session[:ratings]}))
- elsif
- @movies = Movie.all
- end
end
-
+
if params[:sort] == "title"
@movies = @movies.sort_by {|m| m.title}
elsif params[:sort] == "date"
@movies = @movies.sort_by {|m| m.release_date}
end
-
end
def new

0 comments on commit 92bf2ed

Please sign in to comment.