| Module | ScopedSearch::BackwardsCompatibility |
| In: |
lib/scoped_search.rb
|
The BackwardsCompatibility module can be included into ActiveRecord::Base to provide the searchable_on search field definition syntax that is compatible with scoped_seach 1.x
Currently, it is included into ActiveRecord::Base by default, but this may change in the future. So, please uodate to the newer syntax as soon as possible.
Defines fields to search on using a syntax compatible with scoped_search 1.x
# File lib/scoped_search.rb, line 50
50: def searchable_on(*fields)
51:
52: options = fields.last.kind_of?(Hash) ? fields.pop : {}
53: # TODO: handle options?
54:
55: fields.each do |field|
56: if relation = self.reflections.keys.detect { |relation| field.to_s =~ Regexp.new("^#{relation}_(\\w+)$") }
57: scoped_search(:in => relation, :on => $1.to_sym)
58: else
59: scoped_search(:on => field)
60: end
61: end
62: end