我有一个rails应用程序,它有多个带有回形针附件的模型,这些附件都上传到S3.这个应用程序还有一个经常运行的大型测试套件.这样做的缺点是每次测试运行都会将大量文件上传到我们的S3帐户,这使得测试套件运行缓慢.它还会降低开发速度,并要求您具有Internet连接以便处理代码.
有没有合理的方法来设置基于Rails环境的回形针存储机制?理想情况下,我们的测试和开发环境将使用本地文件系统存储,生产环境将使用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
Run Code Online (Sandbox Code Playgroud)
更新:粘性部分是附件:path和:url选项需要根据使用的存储系统而有所不同.
任何建议或建议将不胜感激!:-)