Module: Zable::Search::ActiveRecord::ClassMethods
- Defined in:
- lib/zable/search.rb
Instance Method Summary collapse
- #inherited(subclass) ⇒ Object
-
#searchable(*attr_names) ⇒ Object
Allows
Model.for_search_params
to do equality-based searching for the givenattr_names
.
Instance Method Details
#inherited(subclass) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/zable/search.rb', line 5 def inherited(subclass) subclass.class_eval do scope :for_search_params, -> search_params { inject_search_scopes(search_params) } end super(subclass) end |
#searchable(*attr_names) ⇒ Object
Allows Model.for_search_params
to do equality-based searching for the given attr_names
. Date attributes (ending in “_on”) will take Ruby-parseable date strings as well as the common US case “mm/dd/yyyy”.
searchable :first_name, :last_name, :born_on
17 18 19 20 21 22 23 |
# File 'lib/zable/search.rb', line 17 def searchable(*attr_names) attr_names.each do |attr_name| scope "search_#{attr_name}", -> attr_value do where(attr_name => (attr_name =~ /_on$/ ? parse_date_string(attr_value) : attr_value)) end end end |