Class: BlogPost

Inherits:
ActiveRecord::Base
  • Object
show all
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

Class Method Details

.columns_for_indexObject



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_orderObject



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_atObject 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

#dayObject



110
111
112
# File 'app/models/blog_post.rb', line 110

def day
  published_at.strftime("%d") unless published_at.blank?
end

#monthObject



106
107
108
# File 'app/models/blog_post.rb', line 106

def month
  published_at.strftime("%m") unless published_at.blank?
end

#pathObject



92
93
94
# File 'app/models/blog_post.rb', line 92

def path
  send("#{blog.name_for_path}_post_path", route_params)
end

#published_labelObject



84
85
86
# File 'app/models/blog_post.rb', line 84

def published_label
  published_at ? published_at.to_s(:date) : nil
end

#route_nameObject



95
96
97
# File 'app/models/blog_post.rb', line 95

def route_name
  "#{blog.name_for_path}_post"
end

#route_paramsObject



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_pathObject



5
6
7
8
9
10
# File 'app/models/blog_post.rb', line 5

def set_attachment_file_path
  # 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_sectionObject



12
13
14
15
16
# File 'app/models/blog_post.rb', line 12

def set_attachment_section
  # 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_atObject



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_slugObject



88
89
90
# File 'app/models/blog_post.rb', line 88

def set_slug
  self.slug = name.to_slug
end

#yearObject



102
103
104
# File 'app/models/blog_post.rb', line 102

def year
  published_at.strftime("%Y") unless published_at.blank?
end