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.rb18
1 files changed, 9 insertions, 9 deletions
diff --git a/app/models/blog.rb b/app/models/blog.rb index 495c6eb..322a808 100644 --- a/app/models/blog.rb +++ b/app/models/blog.rb
@@ -1,26 +1,26 @@
1class Blog < ApplicationRecord 1class Blog < ApplicationRecord
2 has_many :records, as: :recordable, inverse_of: :recordable 2 has_many :records, as: :recordable, inverse_of: :recordable
3 3
4 validates :title, :body, presence: true 4 validates :title, presence: true
5 validates :slug, presence: true, format: /\A[-a-z0-9]+\z/ 5 validates :body, presence: true, if: :published
6 validates :slug, presence: true, format: /\A[-a-z0-9]+\z/, if: :published
6 7
7 accepts_nested_attributes_for :records, allow_destroy: true 8 accepts_nested_attributes_for :records, allow_destroy: true
8 9
10 before_validation :set_draft_title
9 before_save :set_published_at 11 before_save :set_published_at
10 12
11 def path 13 def path
12 "/says/#{slug}" 14 "/says/#{slug}"
13 end 15 end
14 16
15 def posted_at 17 private
16 if published 18 def set_draft_title
17 published_at 19 if self.title.blank? and not self.published
18 else 20 self.title = "Untitled draft"
19 updated_at 21 end
20 end 22 end
21 end
22 23
23 private
24 def set_published_at 24 def set_published_at
25 if self.published 25 if self.published
26 if self.published_at.blank? 26 if self.published_at.blank?