Class: CmsBlog
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- CmsBlog
- Extended by:
- FriendlyId
- Includes:
- DmCore::Concerns::FriendlyId, DmCore::Concerns::PublicPrivate, RankedModel
- Defined in:
- app/models/cms_blog.rb
Class Method Summary collapse
-
.recent_posts(options = {user: nil, limit: 5, blog: nil}) ⇒ Object
Grab a list of the recent posts.
Instance Method Summary collapse
-
#any_readable_blogs?(user) ⇒ Boolean
Are any of the blogs readable by this user? One positive is all need…
-
#header_accent_color(default = '') ⇒ Object
——————————————————————————.
-
#header_image(default = nil) ⇒ Object
Return the header image, or a default if not specified ——————————————————————————.
-
#is_published? ⇒ Boolean
——————————————————————————.
-
#model_slug ⇒ Object
——————————————————————————.
-
#show_social_buttons? ⇒ Boolean
——————————————————————————.
Class Method Details
.recent_posts(options = {user: nil, limit: 5, blog: nil}) ⇒ Object
Grab a list of the recent posts. Can pull from all blogs or a specific one.
67 68 69 70 71 72 73 74 |
# File 'app/models/cms_blog.rb', line 67 def self.recent_posts( = {user: nil, limit: 5, blog: nil}) if [:blog].nil? # get all available to user query_blogs = CmsBlog.available_to_user([:user]).map(&:id) else query_blogs = CmsBlog.friendly.find([:blog]) end CmsPost.where(cms_blog_id: query_blogs).includes(:cms_blog, :translations).published.order('published_on DESC').limit([:limit]) end |
Instance Method Details
#any_readable_blogs?(user) ⇒ Boolean
Are any of the blogs readable by this user? One positive is all need…
49 50 51 |
# File 'app/models/cms_blog.rb', line 49 def any_readable_blogs?(user) CmsBlog.all.any? { |b| b.can_be_read_by?(user) } end |
#header_accent_color(default = '') ⇒ Object
60 61 62 |
# File 'app/models/cms_blog.rb', line 60 def header_accent_color(default = '') self.preferred_header_accent_color || default end |
#header_image(default = nil) ⇒ Object
Return the header image, or a default if not specified
55 56 57 |
# File 'app/models/cms_blog.rb', line 55 def header_image(default = nil) self.attributes['header_image'] || default end |
#is_published? ⇒ Boolean
38 39 40 |
# File 'app/models/cms_blog.rb', line 38 def is_published? published end |
#model_slug ⇒ Object
33 34 35 |
# File 'app/models/cms_blog.rb', line 33 def model_slug send("title_#{Account.current.preferred_default_locale}") end |
#show_social_buttons? ⇒ Boolean
43 44 45 |
# File 'app/models/cms_blog.rb', line 43 def && !is_private? end |