From 468d6abb70b3fc358c21f55ab99434bd9b5865b6 Mon Sep 17 00:00:00 2001 From: John Date: Sun, 18 Mar 2012 17:26:54 +0300 Subject: [PATCH] imped simple ratings filter --- app/controllers/movies_controller.rb | 22 ++++++++++++++++------ app/views/movies/index.html.haml | 9 +++++++++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/app/controllers/movies_controller.rb b/app/controllers/movies_controller.rb index b7bada0..322495e 100644 --- a/app/controllers/movies_controller.rb +++ b/app/controllers/movies_controller.rb @@ -7,19 +7,29 @@ class MoviesController < ApplicationController end def index - logger.info params.inspect + #logger.info params.inspect + + @filters = {} + + @movies = if params[:ratings] + params[:ratings].each_key { |k| @filters[k] = true } + Movie.where(:rating => params[:ratings].keys) + else + Movie.all + end + @movies = case params['sort-by'] when 'title' @hilite_title = true - Movie.order('title') + @movies.order('title') when 'release_date' @hilite_release_date = true - Movie.order('release_date') + @movies.order('release_date') else - Movie.all + @movies end - - # @movies = Movie.all + + @all_ratings = Movie.select(:rating).map { |x| x.rating }.uniq end def new diff --git a/app/views/movies/index.html.haml b/app/views/movies/index.html.haml index f95692b..0df9ec0 100644 --- a/app/views/movies/index.html.haml +++ b/app/views/movies/index.html.haml @@ -1,6 +1,15 @@ -# This file is app/views/movies/index.html.haml %h1= link_to 'All Movies', movies_path + += form_tag movies_path, :method => :get do + Include: + - @all_ratings.each do |rating| + = rating + = check_box_tag "ratings[#{rating}]", 1, @filters[rating], :id => "ratings_#{rating}" + = submit_tag 'Refresh' + + %table#movies %thead %tr -- 2.11.4.GIT