Created
May 6, 2015 17:15
-
-
Save bricker/6a02ba22f24cfc0c69f7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class CoolController < ApplicationController | |
before_action :setup_conditions, only: [ :index ] | |
before_action :filter_gender, only: [ :index ] | |
before_action :filter_birthday, only: [ :index ] | |
def index | |
@people = Person.where(@conditions) | |
end | |
private | |
def setup_conditions | |
@conditions = {} | |
end | |
def filter_gender | |
return if !params[:gender] | |
@conditions[:gender] = params[:gender] | |
end | |
def filter_birthday | |
return if !params[:start_date] && !params[:end_date] | |
@conditions[:birthday] = (params.fetch(:start_date, Time.now)..params.fetch(:end_date, Time.now)) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment