Created
September 28, 2018 13:37
-
-
Save rafaelrpbelo/3fd7648a84d5bc32be3e8bfb819b6616 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/model/ad_image.rb | |
class AdImage < ApplicationRecord | |
belongs_to :ad | |
# Com o store: 'ad_images_store' estou usando meu backend que criei no initializer para store | |
# Com o cash: 'ad_images_cache' estou usando meu backend que criei no initializer para cache | |
attachment :image, store: 'ad_images_store', cache: 'ad_images_cache', type: :ad_images | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/initializers/refile.rb | |
if Rails.env.production? | |
require 'refile/s3' | |
default_aws_options = { | |
access_key_id: ENV['S3_KEY'], | |
secret_access_key: ENV['S3_SECRET'], | |
region: ENV['S3_REGION'], | |
bucket: ENV['S3_BUCKET'] | |
} | |
Refile.cache = Refile::S3.new(prefix: 'cache', **default_aws_options) | |
Refile.store = Refile::S3.new(prefix: 'store', **default_aws_options) | |
# Tem que colocar isso pra permitir ele mandar os arquivos para este backend com direct upload | |
Refile.allow_uploads_to << 'ad_images_cache' | |
# Declarando um novo backend para cache | |
Refile.backends['ad_images_cache'] = Refile::S3.new(max_size: 3.megabyte, prefix: 'ad_images/cache', **default_aws_options) | |
# Declarando um novo backend para store | |
Refile.backends['ad_images_store'] = Refile::S3.new(max_size: 3.megabyte, prefix: 'ad_images/store', **default_aws_options) | |
else | |
Refile.backends['ad_images_cache'] = Refile.cache | |
Refile.backends['ad_images_store'] = Refile.store | |
end | |
Refile.types[:ad_images] = Refile::Type.new(:custom_image, | |
content_type: ['image/jpeg', 'image/jpg', 'image/png']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment