-
-
Save anonymous/ec2fd9ad204508f62e1a to your computer and use it in GitHub Desktop.
searching
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) | |
blank.tap do |search| | |
fields.each do |field, _| | |
search |= @model.all(field.to_sym.like => term) | |
end | |
# here, simple is [#<Artiste @fields-stripped>] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment