0

我将资产存储在 Amazon s3 存储桶中,但对于开发模式,我将图像存储在

app/assets/images/spree/products/

文件夹。图像未在服务器渲染上加载,因为狂欢视图中的 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'
4

2 回答 2

1

以下组合最终对我有用最新的 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
于 2014-04-26T22:32:42.293 回答
1

回形针gem提供了 Spree 图像定位功能。

它在 Spree::Image 中配置:

https://github.com/spree/spree/blob/v2.0.4/core/app/models/spree/image.rb#L11-12

这两行列出:

  1. URL - 从您的网络服务器获取图像的 URL
  2. 路径 - 存储图像的文件系统路径

您可以使用这些配置值自定义这些:

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 下的所有文件,一切都应该很好!

于 2013-08-21T15:36:05.920 回答