有没有一种合理的方法根据Rails环境设置paperclip存储机制?理想情况下,我们的测试和开发环境将使用本地文件系统存储,而生产环境将使用S3存储。
我还想将此逻辑提取到某种共享模块中,因为我们有几个模型需要此行为。我想避免像每个模型内部这样的解决方案:
### We don't want to do this in our models...
if Rails.env.production?
has_attached_file :image, :styles => {...},
:path => "images/:uuid_partition/:uuid/:style.:extension",
:storage => :s3,
:url => ':s3_authenticated_url', # generates an expiring url
:s3_credentials => File.join(Rails.root, 'config', 's3.yml'),
:s3_permissions => 'private',
:s3_protocol => 'https'
else
has_attached_file :image, :styles => {...},
:storage => :filesystem
# Default :path and :url should be used for dev/test envs.
end
更新: 粘性部分是附件的:path
和:url
选项需要根据使用的存储系统而异。
非常感谢您的任何建议或建议! :-)