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

@@ -6,11 +6,38 @@ class UserFeedback < ActiveRecord::Base
attr_accessible :body, :user_id, :category, :user_name
validates_presence_of :user, :creator, :body, :category
validate :creator_is_privileged
scope :positive, where("category = ?", "positive")
scope :neutral, where("category = ?", "neutral")
scope :negative, where("category = ?", "negative")
scope :for_user, lambda {|user_id| where("user_id = ?", user_id)}
module SearchMethods
def positive
where("category = ?", "positive")
end
def neutral
where("category = ?", "neutral")
end
def negative
where("category = ?", "negative")
end
def for_user(user_id)
where("user_id = ?", user_id)
end
def search(params)
q = scoped
return q if params.blank?
if params[:user_id]
q = q.for_user(params[:user_id].to_i)
end
q
end
end
extend SearchMethods
def initialize_creator
self.creator_id = CurrentUser.id
end