2017-04-07 106 views
0

我有一个模型,我用回形针存储到S3。回形针 - 上传到不同型号的不同S3网址

在paperclip.rb

bucket_name = (Rails.env != 'production') ? "mcds_staging_fulltext" : 'mcds_fulltext' 
Paperclip::Attachment.default_options.merge!({ 
    storage: :s3, 
    s3_credentials: { 
    bucket: bucket_name 
}, 
url: "#{CUSTOMER}/static_cover_images/:style/:basename.:extension", 
path: "#{CUSTOMER}/static_cover_images/:style/:basename.:extension" 
}) 

model1.rb

has_attached_file :cover_image, styles: { :original => ["100%"], :thumbnail => ["100*100", :png] } 
    validates_attachment_content_type :cover_image, content_type: /\Aimage\/.*\Z/, message: 'Invalid Content Type. Please upload jpg/jpeg/png/gif' 
    validates_attachment_size :cover_image, :in => 0.megabytes..5.megabytes, :message => 'must be smaller than 5 MB' 

这个工程poperly和我的S3图像存储在正确的位置。

现在我有另一个模型,我需要将回形针附件上传到不同的S3位置。

在model2.rb

has_attached_file :xslt 
Paperclip::Attachment.default_options.merge!({url: "#{CUSTOMER}/xslts/:style/:basename.:extension"}) 
validates_attachment_content_type :xslt, content_type: "application/xslt+xml", message: 'Invalid Content Type. Please upload jpg/jpeg/png/gif' 
validates_attachment_size :xslt, :in => 0.megabytes..5.megabytes, :message => 'must be smaller than 5 MB' 

但此附件仍在商店我MODEL1 S3,而不是在MODEL2指定的URL。

我在做什么错?

回答

0

我完全删除了paper_clip.rb文件,并在各个模型中添加了paper_clip配置。

MODEL1:

has_attached_file :file1, 
storage: :s3, 
s3_credentials: { 
bucket: bucket_name 
}, 
url: "#{CUSTOMER}/cover_images/:style/:basename.:extension", 
path: "#{CUSTOMER}/cover_images/:style/:basename.:extension" 

MODEL2:

has_attached_file :file2, 
storage: :s3, 
s3_credentials: { 
bucket: bucket_name 
}, 
url: "#{CUSTOMER}/file2_folder/:style/:basename.:extension", 
path: "#{CUSTOMER}/file2_folder/:style/:basename.:extension" 

这个店theattachment正确differen S3文件夹。