我的资产存储在Amazon s3存储桶中,但对于开发模式,我已将图像存储在
下app/assets/images/spree/products/
文件夹。由于spree视图中的url评估为,因此不会在服务器呈现上加载图像 /spree/products/1/small/vanillabreeze00.jpg?1375747478"
我希望将其更改为/assets/spree/products/1/small/vanillabreeze00.jpg?1375747478 因为这就是图像存在的地方。
我正在使用:
gem 'spree', :github=> 'spree/spree', :branch=> '2-0-stable'
gem 'spree_gateway', :git => 'git://github.com/spree/spree_gateway.git', :branch=> '2-0-stable'
gem 'spree_auth_devise', :github => 'spree/spree_auth_devise', :branch=> '2-0-stable'
gem 'spree_variant_options', :git => 'git://github.com/ScienceInc/spree_variant_options.git', :branch => 'spree2'
答案 0 :(得分:1)
狂欢图片位置功能由paperclip gem提供。
它在Spree :: Image here:
中配置https://github.com/spree/spree/blob/v2.0.4/core/app/models/spree/image.rb#L11-12
这两行列出:
您可以使用以下配置值自定义它们:
https://github.com/spree/spree/blob/v2.0.4/core/app/models/spree/image.rb#L23-24
所以在你的情况下,你可以设置:
Spree::Config[:attachment_url] = '/assets/spree/products/:id/:style/:basename.:extension'
话虽如此。我会建议不要这样做。
存储在Rails中/ app下的内容应该受版本控制。由于这些图像可以上传(创建新图像),删除,修改等等。这会改变这些图像,迫使您一直更新存储在版本控制中的图像。
我建议遵循标准的Spree配置,而不是从
移动图像应用程序/资产/图像/礼包/产品/
到
公共/礼包/产品
您可以放心地从版本控制系统中忽略public / spree下的所有文件,一切都应该很棒!
答案 1 :(得分:1)
以下组合最终为我提供了最新的Spree(2-3稳定版)。将S3.yml
占位符替换为您的实际S3凭据。我一起使用了'雾'和'回形针'宝石。
ruby '2.1.0'
group :development do
gem 'better_errors'
gem 'binding_of_caller'
end
gem 'rails', '4.1.0'
gem 'pg'
gem "font-awesome-rails"
gem 'money', '5.1.1'
gem 'unicorn'
gem 'sass-rails', '4.0.3'
gem 'bootstrap-sass', '3.1.1.0'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '3.1.0'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'
gem 'aws-sdk'
gem 'highline', '1.6.21'
gem 'paperclip'
gem 'fog'
group :doc do
gem 'sdoc', '0.3.20', require: false
end
group :production do
gem 'rails_12factor', '0.0.2'
end
gem 'spree', github: 'spree/spree', branch: 'master'
gem 'spree_gateway', :git => 'https://github.com/spree/spree_gateway.git', :branch => 'master'
gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: 'master'
gem 'stripe', :git => 'https://github.com/stripe/stripe-ruby'
gem 'spree_paypal_express', :github => "radar/better_spree_paypal_express", :branch => "master"
gem 'spree_static_content', github: 'spree/spree_static_content', branch: 'master'
gem 'spree_i18n', github: 'spree/spree_i18n', branch: 'master'
gem 'spree_chimpy', github: 'DynamoMTL/spree_chimpy', branch: 'master'
Spree::Image.attachment_definitions[:attachment][:url] = ':path'
Spree::Image.attachment_definitions[:attachment][:path] = 'spree/products/:id/:style/:basename.:extension'
development:
bucket: "BUCKET_NAME"
access_key_id: "ACCESS_ID"
secret_access_key: "SECRET_KEY"
test:
bucket: "BUCKET_NAME"
access_key_id: "ACCESS_ID"
secret_access_key: "SECRET_KEY"
production:
bucket: "BUCKET_NAME"
access_key_id: "ACCESS_ID"
secret_access_key: "SECRET_KEY"
S3_CONFIG = YAML.load_file("#{Rails.root}/config/s3.yml")[Rails.env]
Paperclip::Attachment.default_options.merge!(
:storage => :fog,
:fog_credentials => {
:provider => 'AWS',
:aws_access_key_id => S3_CONFIG['access_key_id'],
:aws_secret_access_key => S3_CONFIG['secret_access_key'],
:region => 'us-west-2'
},
:fog_directory => S3_CONFIG['bucket'],
:bucket => S3_CONFIG['bucket'],
)
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