Skip to content

Commit

Permalink
Named scopes for comments: in_order, recent, limit.
Browse files Browse the repository at this point in the history
  • Loading branch information
chriseppstein committed May 19, 2009
1 parent ee89c8d commit 4230173
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/comment_methods.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
module ActsAsCommentable
# including this module into your Comment model will give you finders and named scopes
# useful for working with Comments.
# The named scopes are:
# in_order: Returns comments in the order they were created (created_at ASC).
# recent: Returns comments by how recently they were created (created_at DESC).
# limit(N): Return no more than N comments.
module Comment

def self.included(comment_model)
comment_model.extend Finders
comment_model.named_scope :in_order, {:order => 'created_at ASC'}
comment_model.named_scope :recent, {:order => "created_at DESC"}
comment_model.named_scope :limit, lambda {|limit| {:limit => limit}}
end

module Finders
Expand Down

0 comments on commit 4230173

Please sign in to comment.