This commit is contained in:
albert
2011-06-21 12:20:22 -04:00
parent 8a7597bc98
commit 07f8dba7f2
22 changed files with 262 additions and 468 deletions

View File

@@ -39,11 +39,23 @@ class Post < ActiveRecord::Base
scope :for_user, lambda {|user_id| where(["uploader_string = ?", "uploader:#{user_id}"])}
scope :available_for_moderation, lambda {where(["id NOT IN (SELECT pd.post_id FROM post_disapprovals pd WHERE pd.user_id = ?)", CurrentUser.id])}
scope :hidden_from_moderation, lambda {where(["id IN (SELECT pd.post_id FROM post_disapprovals pd WHERE pd.user_id = ?)", CurrentUser.id])}
scope :before_id, lambda {|id| id.present? ? where(["posts.id < ?", id]) : where("TRUE")}
scope :after_id, lambda {|id| id.present? ? where("posts.id > ?", id) : where("true")}
scope :tag_match, lambda {|query| Post.tag_match_helper(query)}
search_methods :tag_match
scope :after_id, Proc.new {|num|
if num.present?
where("id > ?", num.to_i).reorder("id asc")
else
where("true")
end
}
scope :before_id, Proc.new {|num|
if num.present?
where("id < ?", num.to_i).reorder("id desc")
else
where("true")
end
}
module FileMethods
def delete_files
FileUtils.rm_f(file_path)