以下组合最终对我有用最新的 Spree(2-3-stable)。将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'
/config/initializers/spree.rb
Spree::Image.attachment_definitions[:attachment][:url] = ':path'
Spree::Image.attachment_definitions[:attachment][:path] = 'spree/products/:id/:style/:basename.:extension'
/config/s3.yml
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"
/config/initializers/paperclip.rb
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'],
)
/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