Last active
September 7, 2015 19:11
-
-
Save joelibaceta/5d219ae4fe249b9ab36d to your computer and use it in GitHub Desktop.
PaperClip + S3 with a custom path
This file contains hidden or 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/paperclip.rb | |
Paperclip::Attachment.default_options[:s3_host_name] = 's3-us-west-2.amazonaws.com' | |
Paperclip::Attachment.default_options[:url] = ':s3_domain_url' | |
Paperclip::Attachment.default_options[:path] = '/:class/:attachment/:id_partition/:style/:filename.#{Time.now.to_i}' |
This file contains hidden or 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/environments/production.rb | |
config.paperclip_defaults = { | |
:storage => :s3, | |
:s3_credentials => { | |
:bucket => ENV['S3_BUCKET_NAME'], | |
:access_key_id => ENV['AWS_ACCESS_KEY_ID'], | |
:secret_access_key => ENV['AWS_SECRET_ACCESS_KEY'] | |
} | |
} |
This file contains hidden or 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
class SomeModel < ActiveRecord::Base | |
has_attached_file :avatar, styles: { | |
thumb: '100x100>', | |
square: '200x200#', | |
medium: '300x300>' | |
} | |
validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/ | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment