Created
May 26, 2014 12:40
-
-
Save brunoandradd/0ba02a812b44cac5ead5 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
# controller metodo index: | |
def index | |
@consultorios = BuscadorConsultorio.new(params).filtrar | |
end | |
# novo objeto de busca | |
class BuscadorConsultorio | |
def new(opcoes_busca, buscado_padrao = Setor::Consultorio) | |
@opcoes = opcoes_busca | |
@buscador = buscado_padrao | |
end | |
def filtrar | |
consulta = @buscador.where(setor_id: opcoes_busca[:setor_id]) if opcoes_busca[:setor_id].present? | |
consulta = consulta.where(situacao: opcoes_busca[:situacao]) if opcoes_busca[:situacao].present? | |
consulta = consulta.order(:identificacao) | |
consulta.all | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment