diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2018-07-04 10:42:21 -0400 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2018-07-04 10:42:21 -0400 |
commit | d48adb741c5c30ba3f2d3c039a7e342b43add352 (patch) | |
tree | cbc25ac929e73702142a5ec5728a98dc54d88602 /app/models | |
parent | 66353403efcc9c0b16c82ea8ab9860ca8a44aa4c (diff) | |
download | thoughts-d48adb741c5c30ba3f2d3c039a7e342b43add352.tar.gz thoughts-d48adb741c5c30ba3f2d3c039a7e342b43add352.tar.bz2 thoughts-d48adb741c5c30ba3f2d3c039a7e342b43add352.zip |
Added blog drafts
An unpublished post is not viewable unless you are logged in. The "Create record" field is disabled for unpublished posts, though this is only in JavaScript and the backend will not disallow creating records for unpublished posts if forced to. Unpublishing a post does not destroy records for that post. This only applies to blog posts, currently; streams and stream updates cannot be drafted. Unpublished posts still require titles and slugs. There is no autosaving functionality yet. refs #1
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/blog.rb | 21 |
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 | ||
12 | end | 33 | end |