Paperclip 2.8 不使用 `config.paperclip_defaults` 哈希
Paperclip 2.8 Not Using `config.paperclip_defaults` Hash
出于某种原因,我无法让 Paperclip 正确使用 S3。我已经按照文档中的说明配置了它,但是我的所有环境仍然使用 public/system
目录来存储文件。
这是我的配置:
# config/application.rb
config.paperclip_defaults = {
:default_url => "/assets/:attachment/default/:style.jpg",
:storage => :s3,
:s3_protocol => 'https',
:s3_credentials => {
:access_key_id => ENV['S3_KEY'],
:secret_access_key => ENV['S3_SECRET']
},
:bucket => ENV['S3_BUCKET'],
:path => "/:attachment/:id/:style.:extension",
:styles => {
:giant => ["600x600>"],
:huge => ["450x450>"],
:large => ["300x300>"],
:medium => ["200x200>"],
:small => ["100x100>"],
:thumb => ["48x48>"],
:profile => ["34x34>"],
:mini => ["24x24>"]
}
}
我已确认我的 application.yml
中的所有存储桶都已正确命名,S3_KEY
和 S3_SECRET
也都正确。
我正在使用 gem "paperclip", "~> 2.8"
,因为这是一个我们还不担心更新的旧项目。
更新
我现在意识到,以前的开发人员将回形针版本从 ~> 3.1
更改为 ~> 2.8
以在移交项目之前清除一些依赖性问题...但是在他递交之前确实是正确的它交给我,他从来不知道它搞砸了配置。 2.8 版不像 3.0 那样设置全局默认值,所以 config.paperclip_defaults
在我的版本中显然没有意义。
相反,我更新了 application.rb
文件以在 Paperclip::Attachment.default_options
哈希上设置默认值:
# config/application.rb
Paperclip::Attachment.default_options[:default_url] = "/assets/:attachment/default/:style.jpg"
Paperclip::Attachment.default_options[:storage] = :s3
Paperclip::Attachment.default_options[:s3_protocol] = 'https'
Paperclip::Attachment.default_options[:s3_credentials] = {
:access_key_id => ENV['S3_KEY'],
:secret_access_key => ENV['S3_SECRET']
}
Paperclip::Attachment.default_options[:bucket] = ENV['S3_BUCKET'],
Paperclip::Attachment.default_options[:path] = "/:attachment/:id/:style.:extension",
Paperclip::Attachment.default_options[:styles] => {
:giant => ["600x600>"],
:huge => ["450x450>"],
:large => ["300x300>"],
:medium => ["200x200>"],
:small => ["100x100>"],
:thumb => ["48x48>"],
:profile => ["34x34>"],
:mini => ["24x24>"]
}
如我的问题所述,gem "paperclip", "~> 2.8"
不响应 config.paperclip_defaults
哈希,而是从 Paperclip::Attachment.default_options
哈希中获取默认值。
出于某种原因,我无法让 Paperclip 正确使用 S3。我已经按照文档中的说明配置了它,但是我的所有环境仍然使用 public/system
目录来存储文件。
这是我的配置:
# config/application.rb
config.paperclip_defaults = {
:default_url => "/assets/:attachment/default/:style.jpg",
:storage => :s3,
:s3_protocol => 'https',
:s3_credentials => {
:access_key_id => ENV['S3_KEY'],
:secret_access_key => ENV['S3_SECRET']
},
:bucket => ENV['S3_BUCKET'],
:path => "/:attachment/:id/:style.:extension",
:styles => {
:giant => ["600x600>"],
:huge => ["450x450>"],
:large => ["300x300>"],
:medium => ["200x200>"],
:small => ["100x100>"],
:thumb => ["48x48>"],
:profile => ["34x34>"],
:mini => ["24x24>"]
}
}
我已确认我的 application.yml
中的所有存储桶都已正确命名,S3_KEY
和 S3_SECRET
也都正确。
我正在使用 gem "paperclip", "~> 2.8"
,因为这是一个我们还不担心更新的旧项目。
更新
我现在意识到,以前的开发人员将回形针版本从 ~> 3.1
更改为 ~> 2.8
以在移交项目之前清除一些依赖性问题...但是在他递交之前确实是正确的它交给我,他从来不知道它搞砸了配置。 2.8 版不像 3.0 那样设置全局默认值,所以 config.paperclip_defaults
在我的版本中显然没有意义。
相反,我更新了 application.rb
文件以在 Paperclip::Attachment.default_options
哈希上设置默认值:
# config/application.rb
Paperclip::Attachment.default_options[:default_url] = "/assets/:attachment/default/:style.jpg"
Paperclip::Attachment.default_options[:storage] = :s3
Paperclip::Attachment.default_options[:s3_protocol] = 'https'
Paperclip::Attachment.default_options[:s3_credentials] = {
:access_key_id => ENV['S3_KEY'],
:secret_access_key => ENV['S3_SECRET']
}
Paperclip::Attachment.default_options[:bucket] = ENV['S3_BUCKET'],
Paperclip::Attachment.default_options[:path] = "/:attachment/:id/:style.:extension",
Paperclip::Attachment.default_options[:styles] => {
:giant => ["600x600>"],
:huge => ["450x450>"],
:large => ["300x300>"],
:medium => ["200x200>"],
:small => ["100x100>"],
:thumb => ["48x48>"],
:profile => ["34x34>"],
:mini => ["24x24>"]
}
如我的问题所述,gem "paperclip", "~> 2.8"
不响应 config.paperclip_defaults
哈希,而是从 Paperclip::Attachment.default_options
哈希中获取默认值。