Module: ActsAsPublished
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/acts_as_published.rb
Overview
ActsAsPublished
Adds published and draft scopes. Adds published? and draft? methods
add_column :things, :published_start_at, :datetime add_column :things, :published_end_at, :datetime
Defined Under Namespace
Modules: Base, ClassMethods
Instance Method Summary collapse
- #draft? ⇒ Boolean
-
#published? ⇒ Boolean
Instance Methods.
-
#save_as_draft ⇒ Object
For the form.
Instance Method Details
#draft? ⇒ Boolean
59 60 61 62 63 |
# File 'app/models/concerns/acts_as_published.rb', line 59 def draft? return true if published_start_at.blank? || published_start_at > Time.zone.now return true if published_end_at.present? && published_end_at <= Time.zone.now false end |
#published? ⇒ Boolean
Instance Methods
51 52 53 54 55 56 57 |
# File 'app/models/concerns/acts_as_published.rb', line 51 def published? return false if published_start_at.blank? || published_start_at > Time.zone.now return false if published_end_at.present? && published_end_at <= Time.zone.now return false if try(:archived?) true end |
#save_as_draft ⇒ Object
For the form
66 67 68 |
# File 'app/models/concerns/acts_as_published.rb', line 66 def save_as_draft persisted? && published_start_at.blank? && published_end_at.blank? end |