Skip to content

Instantly share code, notes, and snippets.

@bricker
Created May 6, 2015 17:15
Show Gist options
  • Save bricker/6a02ba22f24cfc0c69f7 to your computer and use it in GitHub Desktop.
Save bricker/6a02ba22f24cfc0c69f7 to your computer and use it in GitHub Desktop.
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