about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--app/assets/stylesheets/admin/layout.scss10
-rw-r--r--app/controllers/admin/blogs_controller.rb10
-rw-r--r--app/controllers/blogs_controller.rb2
-rw-r--r--app/models/blog.rb18
-rw-r--r--app/views/admin/blogs/_form.html.haml6
-rw-r--r--app/views/admin/blogs/drafts.html.haml5
-rw-r--r--app/views/admin/blogs/index.html.haml5
-rw-r--r--app/views/admin/blogs/show.html.haml5
-rw-r--r--app/views/blogs/show.html.haml2
-rw-r--r--config/routes.rb6
-rw-r--r--db/migrate/20180704144707_unrequire_blog_slug.rb5
-rw-r--r--db/schema.rb4
12 files changed, 60 insertions, 18 deletions
diff --git a/app/assets/stylesheets/admin/layout.scss b/app/assets/stylesheets/admin/layout.scss index f68cf6a..b825c25 100644 --- a/app/assets/stylesheets/admin/layout.scss +++ b/app/assets/stylesheets/admin/layout.scss
@@ -227,6 +227,16 @@ body {
227 } 227 }
228} 228}
229 229
230#entry-preview-link {
231 a {
232 text-decoration: none;
233
234 &:hover {
235 text-decoration: underline;
236 }
237 }
238}
239
230#flash { 240#flash {
231 display: inline-block; 241 display: inline-block;
232 color: black; 242 color: black;
diff --git a/app/controllers/admin/blogs_controller.rb b/app/controllers/admin/blogs_controller.rb index 9706df3..1035c12 100644 --- a/app/controllers/admin/blogs_controller.rb +++ b/app/controllers/admin/blogs_controller.rb
@@ -9,6 +9,16 @@ class Admin::BlogsController < Admin::AdminController
9 @blogs = Blog.where(published: false).order(updated_at: :desc) 9 @blogs = Blog.where(published: false).order(updated_at: :desc)
10 end 10 end
11 11
12 def show
13 @blog = Blog.find(params[:id])
14
15 if @blog.published
16 redirect_to blog_url(@blog.slug)
17 else
18 render layout: "application"
19 end
20 end
21
12 def new 22 def new
13 @blog = Blog.new 23 @blog = Blog.new
14 end 24 end
diff --git a/app/controllers/blogs_controller.rb b/app/controllers/blogs_controller.rb index f31287b..8ee472e 100644 --- a/app/controllers/blogs_controller.rb +++ b/app/controllers/blogs_controller.rb
@@ -4,7 +4,7 @@ class BlogsController < ApplicationController
4 @blog = Blog.find_by_slug(params[:slug]) 4 @blog = Blog.find_by_slug(params[:slug])
5 5
6 raise ActiveRecord::RecordNotFound unless @blog 6 raise ActiveRecord::RecordNotFound unless @blog
7 raise ActiveRecord::RecordNotFound unless @blog.published or user_signed_in? 7 raise ActiveRecord::RecordNotFound unless @blog.published
8 end 8 end
9 9
10end 10end
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?
diff --git a/app/views/admin/blogs/_form.html.haml b/app/views/admin/blogs/_form.html.haml index 2066aed..12f7a82 100644 --- a/app/views/admin/blogs/_form.html.haml +++ b/app/views/admin/blogs/_form.html.haml
@@ -15,6 +15,12 @@
15 %ul 15 %ul
16 - f.object.errors.full_messages.each do |error| 16 - f.object.errors.full_messages.each do |error|
17 %li= error 17 %li= error
18 - unless f.object.new_record?
19 #entry-preview-link.details-module
20 - if f.object.published
21 = link_to "View post", blog_url(f.object.slug_was), target: "entry-preview"
22 - else
23 = link_to "Preview post", admin_blog_url(f.object), target: "entry-preview"
18 .details-module 24 .details-module
19 .published-field 25 .published-field
20 = f.check_box :published 26 = f.check_box :published
diff --git a/app/views/admin/blogs/drafts.html.haml b/app/views/admin/blogs/drafts.html.haml index 91d3214..8f2d369 100644 --- a/app/views/admin/blogs/drafts.html.haml +++ b/app/views/admin/blogs/drafts.html.haml
@@ -7,4 +7,7 @@
7 %tr{ class: cycle("even", "odd") } 7 %tr{ class: cycle("even", "odd") }
8 %td= blog.title 8 %td= blog.title
9 %td= blog.updated_at.strftime("%B %d, %Y, %l:%M%P") 9 %td= blog.updated_at.strftime("%B %d, %Y, %l:%M%P")
10 %td= link_to "Edit", edit_admin_blog_url(blog) 10 %td
11 %ul.admin-actions
12 %li= link_to "Preview", admin_blog_url(blog)
13 %li= link_to "Edit", edit_admin_blog_url(blog)
diff --git a/app/views/admin/blogs/index.html.haml b/app/views/admin/blogs/index.html.haml index c5db4f1..427d922 100644 --- a/app/views/admin/blogs/index.html.haml +++ b/app/views/admin/blogs/index.html.haml
@@ -7,4 +7,7 @@
7 %tr{ class: cycle("even", "odd") } 7 %tr{ class: cycle("even", "odd") }
8 %td= blog.title 8 %td= blog.title
9 %td= blog.published_at.strftime("%B %d, %Y, %l:%M%P") 9 %td= blog.published_at.strftime("%B %d, %Y, %l:%M%P")
10 %td= link_to "Edit", edit_admin_blog_url(blog) 10 %td
11 %ul.admin-actions
12 %li= link_to "View", blog_url(blog.slug)
13 %li= link_to "Edit", edit_admin_blog_url(blog)
diff --git a/app/views/admin/blogs/show.html.haml b/app/views/admin/blogs/show.html.haml new file mode 100644 index 0000000..7875cab --- /dev/null +++ b/app/views/admin/blogs/show.html.haml
@@ -0,0 +1,5 @@
1= render partial: "blogs/blog", object: @blog
2%footer#blog-footer
3 This draft was last updated on
4 = succeed "." do
5 %time= @blog.updated_at.strftime("%B #{@blog.updated_at.day.ordinalize}, %Y at %-I:%M:%S%P")
diff --git a/app/views/blogs/show.html.haml b/app/views/blogs/show.html.haml index 48c07dc..8ab4523 100644 --- a/app/views/blogs/show.html.haml +++ b/app/views/blogs/show.html.haml
@@ -3,4 +3,4 @@
3%footer#blog-footer 3%footer#blog-footer
4 This entry was posted on 4 This entry was posted on
5 = succeed "." do 5 = succeed "." do
6 %time= @blog.posted_at.strftime("%B #{@blog.posted_at.day.ordinalize}, %Y at %-I:%M:%S%P") 6 %time= @blog.published_at.strftime("%B #{@blog.published_at.day.ordinalize}, %Y at %-I:%M:%S%P")
diff --git a/config/routes.rb b/config/routes.rb index 37e7f90..ac5b84d 100644 --- a/config/routes.rb +++ b/config/routes.rb
@@ -2,7 +2,7 @@ Rails.application.routes.draw do
2 namespace :admin do 2 namespace :admin do
3 get '/', to: 'dashboard#index' 3 get '/', to: 'dashboard#index'
4 4
5 resources :blogs, except: [:show] do 5 resources :blogs do
6 collection do 6 collection do
7 get 'drafts' 7 get 'drafts'
8 end 8 end
@@ -22,9 +22,9 @@ Rails.application.routes.draw do
22 22
23 root "records#index" 23 root "records#index"
24 24
25 get 'says/:slug', to: 'blogs#show' 25 get 'says/:slug', to: 'blogs#show', as: :blog
26 26
27 get 'thinks/:slug', to: 'streams#show' 27 get 'thinks/:slug', to: 'streams#show', as: :stream
28 28
29 mount Pokeviewer::Engine => '/poke3' 29 mount Pokeviewer::Engine => '/poke3'
30end 30end
diff --git a/db/migrate/20180704144707_unrequire_blog_slug.rb b/db/migrate/20180704144707_unrequire_blog_slug.rb new file mode 100644 index 0000000..e9444db --- /dev/null +++ b/db/migrate/20180704144707_unrequire_blog_slug.rb
@@ -0,0 +1,5 @@
1class UnrequireBlogSlug < ActiveRecord::Migration[5.1]
2 def change
3 change_column_null :blogs, :slug, true
4 end
5end
diff --git a/db/schema.rb b/db/schema.rb index d885500..0279d8e 100644 --- a/db/schema.rb +++ b/db/schema.rb
@@ -10,12 +10,12 @@
10# 10#
11# It's strongly recommended that you check this file into your version control system. 11# It's strongly recommended that you check this file into your version control system.
12 12
13ActiveRecord::Schema.define(version: 20180704125527) do 13ActiveRecord::Schema.define(version: 20180704144707) do
14 14
15 create_table "blogs", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" do |t| 15 create_table "blogs", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" do |t|
16 t.string "title" 16 t.string "title"
17 t.text "body" 17 t.text "body"
18 t.string "slug", null: false 18 t.string "slug"
19 t.datetime "created_at", null: false 19 t.datetime "created_at", null: false
20 t.datetime "updated_at", null: false 20 t.datetime "updated_at", null: false
21 t.boolean "published", default: false, null: false 21 t.boolean "published", default: false, null: false