diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/models/blog_category.rb | 2 | ||||
-rw-r--r-- | app/models/blog_post.rb | 26 |
2 files changed, 18 insertions, 10 deletions
diff --git a/app/models/blog_category.rb b/app/models/blog_category.rb index fbd5465..bc0165a 100644 --- a/app/models/blog_category.rb +++ b/app/models/blog_category.rb @@ -1,7 +1,7 @@ class BlogCategory < ActiveRecord::Base has_many :categorizations - has_many :posts, :through => :categorizations, :source => :blog_post, :order => 'published_at DESC' + has_many :posts, :through => :categorizations, :source => :blog_post acts_as_indexed :fields => [:title] diff --git a/app/models/blog_post.rb b/app/models/blog_post.rb index ed1e14c..c9929ce 100644 --- a/app/models/blog_post.rb +++ b/app/models/blog_post.rb @@ -1,5 +1,7 @@ class BlogPost < ActiveRecord::Base - + + default_scope :order => 'published_at DESC' + has_many :comments, :class_name => 'BlogComment', :dependent => :destroy has_many :categorizations @@ -13,19 +15,19 @@ class BlogPost < ActiveRecord::Base has_friendly_id :title, :use_slug => true scope :by_archive, lambda { |archive_date| - where(['published_at between ? and ?', archive_date.beginning_of_month, archive_date.end_of_month]).order("published_at DESC") + where(['published_at between ? and ?', archive_date.beginning_of_month, archive_date.end_of_month]) } scope :by_year, lambda { |archive_year| - where(['published_at between ? and ?', archive_year.beginning_of_year, archive_year.end_of_year]).order("published_at DESC") + where(['published_at between ? and ?', archive_year.beginning_of_year, archive_year.end_of_year]) } - scope :all_previous, where(['published_at <= ?', Time.now.beginning_of_month]).order("published_at DESC") + scope :all_previous, where(['published_at <= ?', Time.now.beginning_of_month]) - scope :live, lambda { where( "published_at < ? and draft = ?", Time.now, false).order("published_at DESC") } + scope :live, where( "published_at <= ? and draft = ?", Time.now, false) - scope :previous, lambda { |i| where(["published_at < ? and draft = ?", i.published_at, false]).order("published_at DESC").limit(1) } - scope :next, lambda { |i| where(["published_at > ? and draft = ?", i.published_at, false]).order("published_at ASC").limit(1) } + scope :previous, lambda { |i| where(["published_at < ? and draft = ?", i.published_at, false]).limit(1) } + # next is now in << self def next self.class.next(self).first @@ -46,6 +48,12 @@ class BlogPost < ActiveRecord::Base end class << self + def next current_record + self.send(:with_exclusive_scope) do + where(["published_at > ? and draft = ?", current_record.published_at, false]).order("published_at ASC") + end + end + def comments_allowed? RefinerySetting.find_or_set(:comments_allowed, true, { :scoping => 'blog' @@ -53,14 +61,14 @@ class BlogPost < ActiveRecord::Base end def uncategorized - posts = BlogPost.live.reject { |p| p.categories.any? } + BlogPost.all.reject { |p| p.categories.any? } end end module ShareThis DEFAULT_KEY = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" - class << self + class << self def key RefinerySetting.find_or_set(:share_this_key, BlogPost::ShareThis::DEFAULT_KEY, { :scoping => 'blog' |