adubrock / PDX911Calls

Logs the Police calls in Portland so residents can search them.
0 stars 4 forks source link

Call.search isn't actually chainable #8

Open davidcelis opened 10 years ago

davidcelis commented 10 years ago
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.

ageoldpun commented 10 years ago

For this one, I made the suggested change, but it still seems like it isn't chainable. I am going to leave this issue open until I find out why.