diff options
author | djones <dgjones@gmail.com> | 2010-09-21 17:20:08 +1200 |
---|---|---|
committer | djones <dgjones@gmail.com> | 2010-09-21 17:20:08 +1200 |
commit | f036f2a46f5c085505aff507f54518df8e283069 (patch) | |
tree | 5dd5bd48059066ceb0fef489d33e42d93e15c5df /app/models | |
parent | 18b2db513d5241738135cfd330e730c63abec277 (diff) | |
download | refinerycms-blog-f036f2a46f5c085505aff507f54518df8e283069.tar.gz refinerycms-blog-f036f2a46f5c085505aff507f54518df8e283069.tar.bz2 refinerycms-blog-f036f2a46f5c085505aff507f54518df8e283069.zip |
added publish date support. fixes bug where categories were showing posts that were technically supposed to be hidden from the end user
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/blog_category.rb | 13 | ||||
-rw-r--r-- | app/models/blog_post.rb | 10 |
2 files changed, 19 insertions, 4 deletions
diff --git a/app/models/blog_category.rb b/app/models/blog_category.rb index 09d32de..c78a7a4 100644 --- a/app/models/blog_category.rb +++ b/app/models/blog_category.rb @@ -8,5 +8,16 @@ class BlogCategory < ActiveRecord::Base validates_uniqueness_of :title has_friendly_id :title, :use_slug => true - + + # this might be able to be optimised a little more + def post_count + count = 0 + + self.posts.each do |p| + count += 1 if p.live? + end + + count + end + end diff --git a/app/models/blog_post.rb b/app/models/blog_post.rb index 0470cf7..a9fe8c2 100644 --- a/app/models/blog_post.rb +++ b/app/models/blog_post.rb @@ -13,11 +13,15 @@ class BlogPost < ActiveRecord::Base default_scope :order => "created_at DESC" if Rails.version < '3.0.0' - named_scope :live, :conditions => {:draft => false} + named_scope :live, lambda { {:conditions => ["published_at < ? and draft = ?", Time.now, false]} } else - scope :live, :conditions => {:draft => false} + scope :live, lambda { where( "published_at < ? and draft = ?", Time.now, false) } end - + + def live? + !draft and published_at <= Time.now + end + def category_ids=(ids) self.categories = ids.reject{|id| id.blank?}.collect {|c_id| BlogCategory.find(c_id.to_i) rescue nil |