我有一个名为 Report 的类,报告是通过 Rake 任务生成的。我还对图像(用户头像)使用回形针,它可以很好地上传到我的 S3 存储桶。这是报告模型的顶部:
require 'csv'
class Report < ActiveRecord::Base
attr_accessible :csv_file, :category
Paperclip.interpolates :category do |attachment, style|
attachment.instance.category.downcase
end
has_attached_file :csv_file,
path: (Rails.env.staging? || Rails.env.production?) ? ":class/:category/:basename.:extension" : ":rails_root/public/system/:class/:category/:basename.:extension"
我的 Paperclip.rb 文件是这样的:
Paperclip.options[:log] = false
Paperclip.options[:command_path] = if Rails.env.dev?
"/usr/local/bin"
else
"/usr/bin"
end
PAPERCLIP_OPTIONS = {
:hash_secret => "HASHSECRETHERE",
:default_url => "http://placehold.it/:style",
:processors => [:thumbnail]
}
PAPERCLIP_STORAGE_OPTIONS = if Rails.env.staging? || Rails.env.production?
{ :storage => :s3,
:s3_credentials => "#{Rails.root}/config/apis/s3.yml",
:s3_permissions => :public_read,
:s3_protocol => :https,
:path => ":class/:attachment/:id_partition/:style/:hash.:extension" }
else
{ :path => ":rails_root/public/system/:class/:attachment/:id_partition/:style/:hash.:extension",
:url => "/system/:class/:attachment/:id_partition/:style/:hash.:extension" }
end
PAPERCLIP_OPTIONS.merge!(PAPERCLIP_STORAGE_OPTIONS)
它将报告保存到:
/system/reports/csv_files/000/000/002/original/general-report-2013-9-25-T-3-56-PM.csv?1380142571
而不是像我的头像那样的 S3:
//s3.amazonaws.com/production/media/avatar-placeholder.gif
有人知道为什么吗?