about summary refs log tree commit diff stats
path: root/app
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2023-10-17 15:05:36 -0400
committerStar Rauchenberger <fefferburbia@gmail.com>2023-10-17 15:05:36 -0400
commit95e7c215df89608a5b10bebb87968c9a713bbf3d (patch)
treeb21785e6483b0286a812dda44082bc735264fb27 /app
parent8d039903f630db0b89f2df44a94f4e5c938bd7bf (diff)
downloadthoughts-95e7c215df89608a5b10bebb87968c9a713bbf3d.tar.gz
thoughts-95e7c215df89608a5b10bebb87968c9a713bbf3d.tar.bz2
thoughts-95e7c215df89608a5b10bebb87968c9a713bbf3d.zip
Added uploading images to blog posts
Diffstat (limited to 'app')
-rw-r--r--app/assets/javascripts/admin/records.coffee2
-rw-r--r--app/assets/stylesheets/admin/layout.scss25
-rw-r--r--app/controllers/admin/blogs_controller.rb2
-rw-r--r--app/models/blog.rb7
-rw-r--r--app/views/admin/blogs/_form.html.haml8
5 files changed, 35 insertions, 9 deletions
diff --git a/app/assets/javascripts/admin/records.coffee b/app/assets/javascripts/admin/records.coffee index 27cdb78..3862b09 100644 --- a/app/assets/javascripts/admin/records.coffee +++ b/app/assets/javascripts/admin/records.coffee
@@ -28,3 +28,5 @@ $(document).on "turbolinks:load", ->
28 $(".tags-input input[type=text]").autocomplete({ 28 $(".tags-input input[type=text]").autocomplete({
29 source: Routes.suggest_tags_path() 29 source: Routes.suggest_tags_path()
30 }) 30 })
31 $(".image-uploads pre").click ->
32 navigator.clipboard.writeText($(this).text());
diff --git a/app/assets/stylesheets/admin/layout.scss b/app/assets/stylesheets/admin/layout.scss index bf15b0d..9585414 100644 --- a/app/assets/stylesheets/admin/layout.scss +++ b/app/assets/stylesheets/admin/layout.scss
@@ -82,19 +82,16 @@ body {
82} 82}
83 83
84#entry-form { 84#entry-form {
85 display: flex; 85 display: grid;
86 grid-template-columns: 73% 27%;
86 height: 100%; 87 height: 100%;
87 88
88 fieldset { 89 fieldset {
89 border: 0; 90 border: 0;
90 } 91 }
91 92
92 #content {
93 width: 77%;
94 }
95
96 #details { 93 #details {
97 width: 23%; 94 min-width: 0;
98 display: flex; 95 display: flex;
99 flex-direction: column; 96 flex-direction: column;
100 padding-left: 0; 97 padding-left: 0;
@@ -201,6 +198,22 @@ body {
201 border-radius: 5px; 198 border-radius: 5px;
202 padding: .5em; 199 padding: .5em;
203 margin-bottom: 1em; 200 margin-bottom: 1em;
201
202 h4 {
203 margin-top: 0;
204 margin-bottom: 0.5em;
205 }
206
207 img {
208 max-width: 100%;
209 }
210}
211
212.image-uploads {
213 pre {
214 overflow: auto;
215 max-width: 100%;
216 }
204} 217}
205 218
206.should-create-record-field { 219.should-create-record-field {
diff --git a/app/controllers/admin/blogs_controller.rb b/app/controllers/admin/blogs_controller.rb index f0ce519..35f3514 100644 --- a/app/controllers/admin/blogs_controller.rb +++ b/app/controllers/admin/blogs_controller.rb
@@ -57,7 +57,7 @@ class Admin::BlogsController < Admin::AdminController
57 private 57 private
58 58
59 def blog_params 59 def blog_params
60 params.require(:blog).permit(:title, :body, :slug, :published, :published_at, :tag_list, records_attributes: [:description, :_destroy]) 60 params.require(:blog).permit(:title, :body, :slug, :published, :published_at, :tag_list, images: [], records_attributes: [:description, :_destroy])
61 end 61 end
62 62
63 def set_section 63 def set_section
diff --git a/app/models/blog.rb b/app/models/blog.rb index 362f69f..6db75ec 100644 --- a/app/models/blog.rb +++ b/app/models/blog.rb
@@ -6,12 +6,15 @@ class Blog < ApplicationRecord
6 has_many :comments 6 has_many :comments
7 belongs_to :user 7 belongs_to :user
8 8
9 has_many_attached :images do |attachable|
10 attachable.variant :thumb, resize_to_limit: [300, 300]
11 end
12
9 validates :title, presence: true 13 validates :title, presence: true
10 validates :body, presence: true, if: :published 14 validates :body, presence: true, if: :published
11 validates :slug, presence: true, format: /\A[-a-z0-9]+\z/, if: :published 15 validates :slug, presence: true, format: /\A[-a-z0-9]+\z/, if: :published
12 validates :user, presence: true 16 validates :user, presence: true
13 17 validates :images, content_type: ['image/png', 'image/jpeg']
14 has_many_attached :images
15 18
16 before_validation :set_draft_title 19 before_validation :set_draft_title
17 before_save :set_published_at 20 before_save :set_published_at
diff --git a/app/views/admin/blogs/_form.html.haml b/app/views/admin/blogs/_form.html.haml index 625c85e..c3720ba 100644 --- a/app/views/admin/blogs/_form.html.haml +++ b/app/views/admin/blogs/_form.html.haml
@@ -39,4 +39,12 @@
39 = builder.label :_destroy, "Create record?" 39 = builder.label :_destroy, "Create record?"
40 .record-description-field 40 .record-description-field
41 = builder.text_area :description, placeholder: "record text" 41 = builder.text_area :description, placeholder: "record text"
42 .details-module.image-uploads
43 %h4 Images
44 - f.object.images.each do |image|
45 = image_tag image.variant(:thumb)
46 = f.hidden_field :images, multiple: true, value: image.signed_id
47 %pre= url_for image
48 %hr
49 = f.file_field :images, multiple: true
42 .details-module= f.submit 50 .details-module= f.submit