From 95e7c215df89608a5b10bebb87968c9a713bbf3d Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Tue, 17 Oct 2023 15:05:36 -0400 Subject: Added uploading images to blog posts --- app/models/blog.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'app/models') 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 has_many :comments belongs_to :user + has_many_attached :images do |attachable| + attachable.variant :thumb, resize_to_limit: [300, 300] + end + validates :title, presence: true validates :body, presence: true, if: :published validates :slug, presence: true, format: /\A[-a-z0-9]+\z/, if: :published validates :user, presence: true - - has_many_attached :images + validates :images, content_type: ['image/png', 'image/jpeg'] before_validation :set_draft_title before_save :set_published_at -- cgit 1.4.1