about summary refs log tree commit diff stats
path: root/app/models/blog.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/blog.rb')
-rw-r--r--app/models/blog.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/app/models/blog.rb b/app/models/blog.rb index 1ace11b..495c6eb 100644 --- a/app/models/blog.rb +++ b/app/models/blog.rb
@@ -6,7 +6,28 @@ class Blog < ApplicationRecord
6 6
7 accepts_nested_attributes_for :records, allow_destroy: true 7 accepts_nested_attributes_for :records, allow_destroy: true
8 8
9 before_save :set_published_at
10
9 def path 11 def path
10 "/says/#{slug}" 12 "/says/#{slug}"
11 end 13 end
14
15 def posted_at
16 if published
17 published_at
18 else
19 updated_at
20 end
21 end
22
23 private
24 def set_published_at
25 if self.published
26 if self.published_at.blank?
27 self.published_at = DateTime.now
28 end
29 else
30 self.published_at = nil
31 end
32 end
12end 33end