module ScopedSearch::BackwardsCompatibility
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.
Public Instance Methods
searchable_on(*fields)
click to toggle source
Defines fields to search on using a syntax compatible with scoped_search 1.x
# File lib/scoped_search.rb, line 50 def searchable_on(*fields) options = fields.last.kind_of?(Hash) ? fields.pop : {} # TODO: handle options? fields.each do |field| if relation = self.reflections.keys.detect { |relation| field.to_s =~ Regexp.new("^#{relation}_(\\w+)$") } scoped_search(:in => relation.to_sym, :on => $1.to_sym) else scoped_search(:on => field) end end end