about summary refs log tree commit diff stats
path: root/app/models/blog.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/blog.rb')
-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