Module: ContentBlock::Publishable
- Extended by:
- ActiveSupport::Concern
- Included in:
- ContentBlock
- Defined in:
- app/models/concerns/content_block/publishable.rb
Overview
DHH-style concern for publish/unpublish behavior. Extracts publishing logic to a reusable, self-contained module.
Instance Method Summary collapse
-
#publish(user: nil) ⇒ Boolean
Publish the content block.
-
#published? ⇒ Boolean
Check if content block is currently published.
-
#unpublish(user: nil) ⇒ Boolean
Unpublish the content block.
Instance Method Details
#publish(user: nil) ⇒ Boolean
Publish the content block.
26 27 28 29 30 31 32 33 34 |
# File 'app/models/concerns/content_block/publishable.rb', line 26 def publish(user: nil) transaction do self.updated_by = user if user && respond_to?(:updated_by=) update!(published: true) end true rescue ActiveRecord::RecordInvalid false end |
#published? ⇒ Boolean
Check if content block is currently published.
51 52 53 |
# File 'app/models/concerns/content_block/publishable.rb', line 51 def published? published == true end |
#unpublish(user: nil) ⇒ Boolean
Unpublish the content block.
39 40 41 42 43 44 45 46 47 |
# File 'app/models/concerns/content_block/publishable.rb', line 39 def unpublish(user: nil) transaction do self.updated_by = user if user && respond_to?(:updated_by=) update!(published: false) end true rescue ActiveRecord::RecordInvalid false end |