Validation for uploaded image type added
This commit is contained in:
parent
3982cdb741
commit
53911f226d
3 changed files with 11 additions and 5 deletions
4
Gemfile
4
Gemfile
|
|
@ -132,3 +132,7 @@ gem 'omniauth-amazon'
|
|||
gem 'omniauth-google-oauth2'
|
||||
gem 'omniauth-github'
|
||||
gem 'omniauth-openid'
|
||||
|
||||
# Validations for ActiveStorage (which replaced Paperclip) are
|
||||
# not yet available in Rails 6.0. So this is a third-party gem.
|
||||
gem 'active_storage_validations'
|
||||
|
|
|
|||
|
|
@ -43,6 +43,8 @@ GEM
|
|||
erubi (~> 1.4)
|
||||
rails-dom-testing (~> 2.0)
|
||||
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
||||
active_storage_validations (0.8.9)
|
||||
rails (>= 5.2.0)
|
||||
activejob (6.0.2.2)
|
||||
activesupport (= 6.0.2.2)
|
||||
globalid (>= 0.3.6)
|
||||
|
|
@ -368,6 +370,7 @@ PLATFORMS
|
|||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
active_storage_validations
|
||||
better_errors
|
||||
binding_of_caller
|
||||
bootsnap
|
||||
|
|
|
|||
|
|
@ -3,13 +3,12 @@ class Screenshot < ApplicationRecord
|
|||
belongs_to :user, inverse_of: :screenshots
|
||||
|
||||
# Use paperclip gem to handle image files related to screenshots
|
||||
# After migration from Paperclip to ActiveStorage:
|
||||
has_one_attached :image
|
||||
|
||||
# has_attached_file :image,
|
||||
# styles: { :large => '800x600>', :thumb => '160x120>' },
|
||||
# default_url: '/images/dummy/no-screenshots-available.svg',
|
||||
# path: ':rails_root/public/screenshots/:id_partition/:style.png',
|
||||
# url: '/screenshots/:id_partition/:style.png'
|
||||
# Validate using 'active_storage_validations' gem
|
||||
validates :image, attached: true, content_type: { in: 'image/png', message: 'is not a valid PNG image file' }
|
||||
|
||||
#validates_attachment_content_type :image, :content_type => 'image/png'
|
||||
#validates_with AttachmentSizeValidator, :attributes => :image, :less_than => 5.megabytes
|
||||
# validate :validate_image_is_unique
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue