Skip to content
This repository has been archived by the owner on Jul 29, 2021. It is now read-only.

Update publish.rb #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/mongoid/publish.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module Publish
field :published, :type => Boolean, :default => false

scope :published, -> { where(:published => true, :published_at.lte => Time.now) }
scope :draft, -> { where(:published => false) }

before_save :set_published_at
end
Expand All @@ -23,6 +24,12 @@ def publish!
self.published_at = Time.now
self.save
end

def unpublish!
self.published = false
self.published_at = nil
self.save
end

def publication_status
self.published? ? self.published_at : "draft"
Expand All @@ -40,4 +47,4 @@ def list(includes_drafts=true)
end

end
end
end