-
-
Save kalleth/231e7a6ed44f6f57c64f to your computer and use it in GitHub Desktop.
searching.rb
This file contains 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
def build_search(initial_term, fields, child_fields) | |
term = "%#{initial_term}%" | |
simple = fields.nil? ? blank : build_simple_searches(term, fields) | |
# here, simple is [] | |
complex = child_fields.nil? ? blank : build_complex_searches(term, child_fields) | |
simple | complex | |
end | |
def build_simple_searches(term, fields) | |
search = blank | |
fields.each do |field, _| | |
search |= @model.all(field.to_sym.like => term) | |
end | |
search | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment