rails paperclip default image with S3

柔情痞子 提交于 2019-12-03 00:21:00
Casper Fabricius

I use paperclip with S3 with default images in the public folder. It works fine. My default_url statement looks like this:

:default_url => '/images/:attachment/missing_:style.png'

which means that for my attachment named avatar, setup with the styles small and large, I must create and put these images in the public dir:

  • /images/avatar/missing_small.png
  • /images/avatar/missing_large.png

It's pretty well documented.

For your reference, or in the case the problem is really somewhere else, here is my full paperclip statement:

has_attached_file :avatar,
  :styles => { :small => '60x60#', :large => '300x300#' }, :default_style => :large,
  :storage => :s3,
  :default_url => '/images/:attachment/missing_:style.png',
  :path => "users/:id/avatar/:style.:extension",
  :bucket => "bucket name",
  :s3_credentials => {
    :access_key_id => "access key id",
    :secret_access_key => "secret access key"
  },
  :url => ":s3_alias_url", # These two are only required when you alias S3 - e.g. want to use cdn.example.com rather than s3.amazonaws.com
  :s3_host_alias => "my.aws.alias" 

try this out: :default_url => ActionController::Base.helpers.asset_path('missing.png')

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!