Cleanup next and previous stuff.
This commit is contained in:
parent
2537923034
commit
5eaad8997f
1 changed files with 4 additions and 7 deletions
|
@ -8,7 +8,6 @@ module Refinery
|
||||||
is_seo_meta if self.table_exists?
|
is_seo_meta if self.table_exists?
|
||||||
|
|
||||||
default_scope :order => 'published_at DESC'
|
default_scope :order => 'published_at DESC'
|
||||||
#.first & .last will be reversed -- consider a with_exclusive_scope on these?
|
|
||||||
|
|
||||||
belongs_to :author, :class_name => 'Refinery::User', :foreign_key => :user_id, :readonly => true
|
belongs_to :author, :class_name => 'Refinery::User', :foreign_key => :user_id, :readonly => true
|
||||||
|
|
||||||
|
@ -41,11 +40,11 @@ module Refinery
|
||||||
self.per_page = Refinery::Blog.posts_per_page
|
self.per_page = Refinery::Blog.posts_per_page
|
||||||
|
|
||||||
def next
|
def next
|
||||||
self.class.next(self).first
|
self.class.next(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
def prev
|
def prev
|
||||||
self.class.previous(self).first
|
self.class.previous(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
def live?
|
def live?
|
||||||
|
@ -78,7 +77,7 @@ module Refinery
|
||||||
end
|
end
|
||||||
|
|
||||||
def previous(item)
|
def previous(item)
|
||||||
published_before(item.published_at).limit(1)
|
published_before(item.published_at).first
|
||||||
end
|
end
|
||||||
|
|
||||||
def uncategorized
|
def uncategorized
|
||||||
|
@ -86,9 +85,7 @@ module Refinery
|
||||||
end
|
end
|
||||||
|
|
||||||
def next(current_record)
|
def next(current_record)
|
||||||
self.send(:with_exclusive_scope) do
|
where(["published_at > ? and draft = ?", current_record.published_at, false]).first
|
||||||
where(["published_at > ? and draft = ?", current_record.published_at, false]).order("published_at ASC")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def published_before(date=Time.now)
|
def published_before(date=Time.now)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue