From d48adb741c5c30ba3f2d3c039a7e342b43add352 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Wed, 4 Jul 2018 10:42:21 -0400 Subject: 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 --- app/models/blog.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'app/models/blog.rb') 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 accepts_nested_attributes_for :records, allow_destroy: true + before_save :set_published_at + def path "/says/#{slug}" end + + def posted_at + if published + published_at + else + updated_at + end + end + + private + def set_published_at + if self.published + if self.published_at.blank? + self.published_at = DateTime.now + end + else + self.published_at = nil + end + end end -- cgit 1.4.1