class Call < ActiveRecord::Base
def self.search(term)
Call.where("agency LIKE '%#{term}%'
OR call_type LIKE '%#{term}%'
OR address LIKE '%#{term}%'
OR updated_at LIKE '%#{term}%'
OR strftime('%m/%d/%Y', updated_at) LIKE '%#{term}%'
OR strftime('%m/%Y', updated_at) LIKE '%#{term}%'")
end
end
Because the call in self.search is Call.where instead of self.where (or just where if you like the implicit self), you lose scopes such as your pagination in the controller. You end up calling where directly on Call instead of whatever ActiveRecord::Relation you may currently be working with.
Because the call in
self.search
isCall.where
instead ofself.where
(or justwhere
if you like the implicit self), you lose scopes such as your pagination in the controller. You end up callingwhere
directly on Call instead of whatever ActiveRecord::Relation you may currently be working with.