From 45146e0fbb9edc1fa5a41aae57fda5dcb9f8dfe6 Mon Sep 17 00:00:00 2001 From: Torsten Date: Sun, 18 Jun 2023 16:21:41 +0300 Subject: [PATCH] only allow pictures for upload --- app/models/picture.rb | 1 + app/models/story.rb | 1 + app/uploaders/picture_uploader.rb | 8 +++----- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/models/picture.rb b/app/models/picture.rb index 0bd896c..1a6bc4b 100644 --- a/app/models/picture.rb +++ b/app/models/picture.rb @@ -5,5 +5,6 @@ class Picture < ApplicationRecord validates :text, length: { maximum: 80 } validates :happened, presence: true + validates :picture, presence: true end diff --git a/app/models/story.rb b/app/models/story.rb index e55ab4b..dff5458 100644 --- a/app/models/story.rb +++ b/app/models/story.rb @@ -5,6 +5,7 @@ class Story < ApplicationRecord validates :text, length: { minimum: 5 , maximum: 1000 } validates :header , length: { minimum: 5 , maximum: 400} + validates :picture, presence: true def name header diff --git a/app/uploaders/picture_uploader.rb b/app/uploaders/picture_uploader.rb index 42856bd..33afc52 100644 --- a/app/uploaders/picture_uploader.rb +++ b/app/uploaders/picture_uploader.rb @@ -31,11 +31,9 @@ class PictureUploader < CarrierWave::Uploader::Base # process resize_to_fit: [50, 50] # end - # Add an allowlist of extensions which are allowed to be uploaded. - # For images you might use something like this: - # def extension_allowlist - # %w(jpg jpeg gif png) - # end + def content_type_allowlist + /image\// + end # Override the filename of the uploaded files: # Avoid using model.id or version_name here, see uploader/store.rb for details.