refactored search

This commit is contained in:
albert
2013-01-10 17:45:52 -05:00
parent 13271e9bf5
commit 8749c43b3e
85 changed files with 946 additions and 304 deletions

View File

@@ -5,7 +5,25 @@ class PoolVersion < ActiveRecord::Base
belongs_to :pool
belongs_to :updater, :class_name => "User"
before_validation :initialize_updater
scope :for_user, lambda {|user_id| where("updater_id = ?", user_id)}
module SearchMethods
def for_user(user_id)
where("updater_id = ?", user_id)
end
def search(params)
q = scoped
return q if params.blank?
if params[:updater_id]
q = q.for_user(params[:updater_id].to_i)
end
q
end
end
extend SearchMethods
def initialize_updater
self.updater_id = CurrentUser.id