Skip to content

Instantly share code, notes, and snippets.

@batasrki
Created August 29, 2008 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save batasrki/8031 to your computer and use it in GitHub Desktop.
Save batasrki/8031 to your computer and use it in GitHub Desktop.
class User < ActiveRecord::Base
# Blog related
def last_posts(published_only = false, limit = MAX_BLOG_ENTRIES)
conditions = nil
conditions = 'draft=false' if published_only
self.posts.find(:all, :select => 'id, title, preview, draft, created_at',
:conditions => conditions, :limit => limit,
:order => "created_at DESC")
end
def posts_count(published_only)
if published_only then self.published_posts.count else self.posts.count end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment