aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/blog_post.rb
diff options
context:
space:
mode:
authorJoe Sak <joe@joesak.com>2010-11-20 11:35:08 -0600
committerJoe Sak <joe@joesak.com>2010-11-20 11:35:08 -0600
commita214b9e7168890ce52c3336350663669cb938ce5 (patch)
treec815cd3f8feef60163d8ae1381550ea217d81ccd /app/models/blog_post.rb
parent43d8c3a7ff35b4ec79767a204c14b33d90f7f1ab (diff)
downloadrefinerycms-blog-a214b9e7168890ce52c3336350663669cb938ce5.tar.gz
refinerycms-blog-a214b9e7168890ce52c3336350663669cb938ce5.tar.bz2
refinerycms-blog-a214b9e7168890ce52c3336350663669cb938ce5.zip
Added Next, Previous Article & Home navigation
Diffstat (limited to 'app/models/blog_post.rb')
-rw-r--r--app/models/blog_post.rb30
1 files changed, 22 insertions, 8 deletions
diff --git a/app/models/blog_post.rb b/app/models/blog_post.rb
index 562a9b9..471be72 100644
--- a/app/models/blog_post.rb
+++ b/app/models/blog_post.rb
@@ -9,27 +9,41 @@ class BlogPost < ActiveRecord::Base
validates_uniqueness_of :title
has_friendly_id :title, :use_slug => true
-
- default_scope :order => "published_at DESC"
if Rails.version < '3.0.0'
- named_scope :by_archive, lambda { |archive_date| {:conditions => ['published_at between ? and ?', archive_date.beginning_of_month, archive_date.end_of_month]} }
+ named_scope :by_archive, lambda { |archive_date| {:conditions => ['published_at between ? and ?', archive_date.beginning_of_month, archive_date.end_of_month], :order => "published_at DESC"} }
else
scope :by_archive, lambda { |archive_date|
- where ['published_at between ? and ?', archive_date.beginning_of_month, archive_date.end_of_month]
+ where(['published_at between ? and ?', archive_date.beginning_of_month, archive_date.end_of_month]).order("published_at DESC")
}
end
if Rails.version < '3.0.0'
- named_scope :all_previous, :conditions => ['published_at <= ?', Time.now.beginning_of_month]
+ named_scope :all_previous, :conditions => ['published_at <= ?', Time.now.beginning_of_month], :order => "published_at DESC"
else
- scope :all_previous, where(['published_at <= ?', Time.now.beginning_of_month])
+ scope :all_previous, where(['published_at <= ?', Time.now.beginning_of_month]).order("published_at DESC")
end
if Rails.version < '3.0.0'
- named_scope :live, lambda { {:conditions => ["published_at < ? and draft = ?", Time.now, false]} }
+ named_scope :live, lambda { {:conditions => ["published_at < ? and draft = ?", Time.now, false], :order => "published_at DESC"} }
+ else
+ scope :live, lambda { where( "published_at < ? and draft = ?", Time.now, false).order("published_at DESC") }
+ end
+
+ if Rails.version < '3.0.0'
+ named_scope :previous, lambda { |i| { :conditions => ["published_at < ?", i.published_at], :order => "published_at DESC", :limit => 1 } }
+ named_scope :next, lambda { |i| { :condtions => ["published_at > ?", i.published_at], :order => "published_at ASC", :limit => 1 } }
else
- scope :live, lambda { where( "published_at < ? and draft = ?", Time.now, false) }
+ scope :previous, lambda { |i| where(["published_at < ?", i.published_at]).order("published_at DESC").limit(1) }
+ scope :next, lambda { |i| where(["published_at > ?", i.published_at]).order("published_at ASC").limit(1) }
+ end
+
+ def next
+ self.class.next(self).first
+ end
+
+ def prev
+ self.class.previous(self).first
end
def live?