improved search methods

This commit is contained in:
albert
2013-01-11 17:13:55 -05:00
parent c7ffda81bf
commit 72b7651169
14 changed files with 93 additions and 4 deletions

View File

@@ -14,6 +14,17 @@ class CommentVote < ActiveRecord::Base
destroy_all("created_at < ?", 14.days.ago)
end
def self.search(params)
q = scoped
return q if params.blank?
if params[:comment_id]
q = q.where("comment_id = ?", params[:comment_id].to_i)
end
q
end
def validate_user_can_vote
if !user.can_comment_vote?
errors.add :user, "can not comment vote"