Class: BcmsBlog::BlogPost
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- BcmsBlog::BlogPost
- Defined in:
- app/models/bcms_blog/blog_post.rb
Constant Summary collapse
- INCORRECT_PARAMETERS =
"Incorrect parameters. This is probably because you are trying to view the " + "portlet through the CMS interface, and so we have no way of knowing what " + "post(s) to show"
Class Method Summary collapse
Instance Method Summary collapse
-
#after_publish_with_set_published_at ⇒ Object
(also: #after_publish)
This is necessary because, oddly, the publish! method in the Publishing behaviour sends an update query directly to the database, bypassing callbacks, so published_at does not get set by our set_published_at callback.
-
#attachment ⇒ Object
Return true if this model has an attachment.
- #day ⇒ Object
- #month ⇒ Object
- #path ⇒ Object
- #published_label ⇒ Object
- #route_name ⇒ Object
- #route_params ⇒ Object
- #set_published_at ⇒ Object
- #set_slug ⇒ Object
- #year ⇒ Object
Class Method Details
.columns_for_index ⇒ Object
68 69 70 71 |
# File 'app/models/bcms_blog/blog_post.rb', line 68 def self.columns_for_index [ {:label => "Name", :method => :name, :order => "name" }, {:label => "Published At", :method => :published_label, :order => "published_at" } ] end |
.default_order ⇒ Object
64 65 66 |
# File 'app/models/bcms_blog/blog_post.rb', line 64 def self.default_order "created_at desc" end |
Instance Method Details
#after_publish_with_set_published_at ⇒ Object Also known as: after_publish
This is necessary because, oddly, the publish! method in the Publishing behaviour sends an update query directly to the database, bypassing callbacks, so published_at does not get set by our set_published_at callback.
51 52 53 54 55 56 57 |
# File 'app/models/bcms_blog/blog_post.rb', line 51 def after_publish_with_set_published_at if published_at.nil? self.published_at = Time.now self.save! end after_publish_without_set_published_at if respond_to? :after_publish_without_set_published_at end |
#attachment ⇒ Object
Return true if this model has an attachment
104 105 106 |
# File 'app/models/bcms_blog/blog_post.rb', line 104 def !file.blank? end |
#day ⇒ Object
99 100 101 |
# File 'app/models/bcms_blog/blog_post.rb', line 99 def day published_at.strftime("%d") unless published_at.blank? end |
#month ⇒ Object
95 96 97 |
# File 'app/models/bcms_blog/blog_post.rb', line 95 def month published_at.strftime("%m") unless published_at.blank? end |
#path ⇒ Object
81 82 83 |
# File 'app/models/bcms_blog/blog_post.rb', line 81 def path send("#{blog.name_for_path}_post_path", route_params) end |
#published_label ⇒ Object
73 74 75 |
# File 'app/models/bcms_blog/blog_post.rb', line 73 def published_label published_at ? published_at.to_s(:date) : nil end |
#route_name ⇒ Object
84 85 86 |
# File 'app/models/bcms_blog/blog_post.rb', line 84 def route_name "#{blog.name_for_path}_post" end |
#route_params ⇒ Object
87 88 89 |
# File 'app/models/bcms_blog/blog_post.rb', line 87 def route_params {:year => year, :month => month, :day => day, :slug => slug} end |
#set_published_at ⇒ Object
42 43 44 45 46 |
# File 'app/models/bcms_blog/blog_post.rb', line 42 def set_published_at if !published_at && publish_on_save self.published_at = Time.now end end |
#set_slug ⇒ Object
77 78 79 |
# File 'app/models/bcms_blog/blog_post.rb', line 77 def set_slug self.slug = name.to_slug end |
#year ⇒ Object
91 92 93 |
# File 'app/models/bcms_blog/blog_post.rb', line 91 def year published_at.strftime("%Y") unless published_at.blank? end |