Class: BlogPost
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- BlogPost
- Defined in:
- app/models/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.
- #day ⇒ Object
- #month ⇒ Object
- #path ⇒ Object
- #published_label ⇒ Object
- #route_name ⇒ Object
- #route_params ⇒ Object
- #set_attachment_file_path ⇒ Object
- #set_attachment_section ⇒ Object
- #set_published_at ⇒ Object
- #set_slug ⇒ Object
- #year ⇒ Object
Class Method Details
.columns_for_index ⇒ Object
79 80 81 82 |
# File 'app/models/blog_post.rb', line 79 def self.columns_for_index [ {:label => "Name", :method => :name, :order => "name" }, {:label => "Published", :method => :published_label, :order => "published" } ] end |
.default_order ⇒ Object
75 76 77 |
# File 'app/models/blog_post.rb', line 75 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.
62 63 64 65 66 67 68 |
# File 'app/models/blog_post.rb', line 62 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 |
#day ⇒ Object
110 111 112 |
# File 'app/models/blog_post.rb', line 110 def day published_at.strftime("%d") unless published_at.blank? end |
#month ⇒ Object
106 107 108 |
# File 'app/models/blog_post.rb', line 106 def month published_at.strftime("%m") unless published_at.blank? end |
#path ⇒ Object
92 93 94 |
# File 'app/models/blog_post.rb', line 92 def path send("#{blog.name_for_path}_post_path", route_params) end |
#published_label ⇒ Object
84 85 86 |
# File 'app/models/blog_post.rb', line 84 def published_label published_at ? published_at.to_s(:date) : nil end |
#route_name ⇒ Object
95 96 97 |
# File 'app/models/blog_post.rb', line 95 def route_name "#{blog.name_for_path}_post" end |
#route_params ⇒ Object
98 99 100 |
# File 'app/models/blog_post.rb', line 98 def route_params {:year => year, :month => month, :day => day, :slug => slug} end |
#set_attachment_file_path ⇒ Object
5 6 7 8 9 10 |
# File 'app/models/blog_post.rb', line 5 def # The default behavior is use /attachments/file.txt for the attachment path, # assuming file.txt was the name of the file the user uploaded # You should override this with your own strategy for setting the attachment path super end |
#set_attachment_section ⇒ Object
12 13 14 15 16 |
# File 'app/models/blog_post.rb', line 12 def # The default behavior is to put all attachments in the root section # Override this method if you would like to change that super end |
#set_published_at ⇒ Object
53 54 55 56 57 |
# File 'app/models/blog_post.rb', line 53 def set_published_at if !published_at && publish_on_save self.published_at = Time.now end end |
#set_slug ⇒ Object
88 89 90 |
# File 'app/models/blog_post.rb', line 88 def set_slug self.slug = name.to_slug end |
#year ⇒ Object
102 103 104 |
# File 'app/models/blog_post.rb', line 102 def year published_at.strftime("%Y") unless published_at.blank? end |