about summary refs log tree commit diff stats
path: root/app/models
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/models
parent8d039903f630db0b89f2df44a94f4e5c938bd7bf (diff)
downloadthoughts-95e7c215df89608a5b10bebb87968c9a713bbf3d.tar.gz
thoughts-95e7c215df89608a5b10bebb87968c9a713bbf3d.tar.bz2
thoughts-95e7c215df89608a5b10bebb87968c9a713bbf3d.zip
Added uploading images to blog posts
Diffstat (limited to 'app/models')
-rw-r--r--app/models/blog.rb7
1 files changed, 5 insertions, 2 deletions
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