Skip to content

Commit

Permalink
gem active_storage_validations
Browse files Browse the repository at this point in the history
  • Loading branch information
yshmarov committed May 14, 2021
1 parent c350b03 commit 32ebf91
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,5 @@ gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'devise'
gem "faker"
gem "aws-sdk-s3", require: false
gem 'active_storage_validations'
gem 'mini_magick', '>= 4.9.5'
5 changes: 5 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ GEM
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
active_storage_validations (0.9.3)
rails (>= 5.2.0)
activejob (6.1.3.1)
activesupport (= 6.1.3.1)
globalid (>= 0.3.6)
Expand Down Expand Up @@ -122,6 +124,7 @@ GEM
mini_mime (>= 0.1.1)
marcel (1.0.1)
method_source (1.0.0)
mini_magick (4.11.0)
mini_mime (1.0.3)
minitest (5.14.4)
msgpack (1.4.2)
Expand Down Expand Up @@ -232,6 +235,7 @@ PLATFORMS
x86_64-linux

DEPENDENCIES
active_storage_validations
aws-sdk-s3
bootsnap (>= 1.4.4)
byebug
Expand All @@ -240,6 +244,7 @@ DEPENDENCIES
faker
jbuilder (~> 2.7)
listen (~> 3.3)
mini_magick (>= 4.9.5)
pg (~> 1.1)
puma (~> 5.0)
rack-mini-profiler (~> 2.0)
Expand Down
5 changes: 5 additions & 0 deletions app/models/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ class Post < ApplicationRecord
has_one_attached :avatar
has_many_attached :images

validates :avatar, attached: true, dimension: { width: { min: 800, max: 2400 } },
content_type: [:png, :jpg, :jpeg], size: { less_than: 100.kilobytes , message: 'is not given between size' }

validates :images, attached: true, limit: { min: 1, max: 3 }, content_type: [:png, :jpg, :jpeg, :mp3]

def to_s
title
end
Expand Down
5 changes: 3 additions & 2 deletions app/views/posts/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
<strong>Images:</strong>
<% if @post.images.attached? %>
<% @post.images.each do |attachment| %>
<%= attachment %>
<%= link_to "Delte attachment", purge_attachment_path(attachment), method: :delete %>
<br>
<% if attachment.image? %>
<%= image_tag attachment, width: "200px" %>
<% elsif attachment.audio? %>
Expand All @@ -30,6 +29,8 @@
<% else %>
<%= link_to attachment.filename, rails_blob_path(attachment, disposition: "attachment") %>
<% end %>
<br>
<%= link_to "Delte attachment", purge_attachment_path(attachment), method: :delete %>
<% end %>
<% end %>
</p>
Expand Down

0 comments on commit 32ebf91

Please sign in to comment.