about summary refs log tree commit diff stats
path: root/app/models/blog.rb
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2018-07-04 11:46:13 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2018-07-04 11:46:13 -0400
commite11dedec034c4180985adf4a9f176b07121f0a41 (patch)
tree7f4320d562f37775cbc8ae390540da03a2d92d77 /app/models/blog.rb
parentd48adb741c5c30ba3f2d3c039a7e342b43add352 (diff)
downloadthoughts-e11dedec034c4180985adf4a9f176b07121f0a41.tar.gz
thoughts-e11dedec034c4180985adf4a9f176b07121f0a41.tar.bz2
thoughts-e11dedec034c4180985adf4a9f176b07121f0a41.zip
Blog drafts no longer require slugs
They do still technically require titles, but the engine will fill in "Untitled draft" if it is left blank. Unpublished posts can be viewed at a different URL than published posts would be. Quick links to view published and unpublished posts have been added to the admin panel.

refs #1
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?