Class: LeanCms::Post
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- LeanCms::Post
- Defined in:
- app/models/lean_cms/post.rb
Class Method Summary collapse
-
.find_by_slug!(slug) ⇒ Object
Class method to find by slug.
Instance Method Summary collapse
-
#excerpt_or_body(length: 200) ⇒ Object
Get excerpt or truncated body.
-
#published? ⇒ Boolean
Check if post is published.
Class Method Details
.find_by_slug!(slug) ⇒ Object
Class method to find by slug
30 31 32 |
# File 'app/models/lean_cms/post.rb', line 30 def self.find_by_slug!(slug) find_by!(slug: slug) end |
Instance Method Details
#excerpt_or_body(length: 200) ⇒ Object
Get excerpt or truncated body
40 41 42 |
# File 'app/models/lean_cms/post.rb', line 40 def excerpt_or_body(length: 200) excerpt.presence || body.to_plain_text.truncate(length) end |
#published? ⇒ Boolean
Check if post is published
35 36 37 |
# File 'app/models/lean_cms/post.rb', line 35 def published? status == 'published' && published_at.present? && published_at <= Time.current end |