gob*_*tri 2 ruby-on-rails heroku amazon-s3 spree ruby-on-rails-4
我需要配置我在Amazon S3上的图像,但是当我试图这样做的版本下2-2稳定的狂欢,我才意识到,这个配置被移动从管理面板.
我在某处读到这个配置会产生一些问题,因此在2-2上删除了它.但我认为功能仍然以某种方式工作.
当我尝试将这些配置添加到我的config/initialize/spree.rb时,我收到错误,因为这些首选项不再存在.
preference :s3_access_key, :string
preference :s3_bucket, :string
preference :s3_secret, :string
Run Code Online (Sandbox Code Playgroud)
这些偏好在2-1稳定但不在2-2稳定上找到
https://github.com/spree/spree/blob/2-1-stable/core/app/models/spree/app_configuration.rb https://github.com/spree/spree/blob/2-2-stable /core/app/models/spree/app_configuration.rb
有没有办法让它与Heroku一起使用?
这是Spree提交的更改以及有关如何进行配置更改的一些说明. https://github.com/spree/spree/commit/b1d6c5e4b9801d888cc76c05116b814945122207
我的理解是你仍然可以使用paperclip来管理上传到S3,我已经使用他们的指令成功完成了上传.但是,我在S3上获取正确配置的保存路径时遇到了问题.这可能会让你开始...在环境配置文件中放入以下内容:
# Paperclip configs
config.paperclip_defaults = {
:storage => :s3,
:bucket => ENV['S3_BUCKET_NAME'],
:s3_credentials => {
:access_key_id => ENV['AWS_ACCESS_KEY_ID'],
:secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
}
}
Run Code Online (Sandbox Code Playgroud)
我使用环境变量作为S3凭证,因此您的很可能会有所不同.这段代码已经使上传文件到S3工作了,就像我说的那样,我只是不能强制上传特定的文件路径.希望有所帮助.
编辑 - 附加信息:
我将以下内容添加到spree.rb初始化程序中,以定义自定义上载路径和自定义URL路径.
# S3 upload path and url path configuration
Spree::Image.attachment_definitions[:attachment][:path] = 'products/:id/:style/:basename.:extension'
Spree::Image.attachment_definitions[:attachment][:url] = 'products/:id/:style/:basename.:extension'
Run Code Online (Sandbox Code Playgroud)
要更改默认上传大小,您可以覆盖Spree图像装饰器模型.因此,在app/models下添加一个spree目录并添加一个名为image_decorator.rb的文件.然后,您可以使用以下内容控制尺寸:
Spree::Image.class_eval do
attachment_definitions[:attachment][:styles] = {
:mini => '48x48>', # thumbs under image
:small => '350x700>', # images on category view
:product => '1024x768>', # full product image
:large => '600x600>' # light box image
}
end
Run Code Online (Sandbox Code Playgroud)
查看此页面了解具体信息 - > http://guides.spreecommerce.com/developer/logic.html
总而言之,您可以通过更新环境初始化程序,Spree初始化程序和覆盖spree image_decorator模型来执行所有常规映像/ S3配置.
归档时间: |
|
查看次数: |
1330 次 |
最近记录: |