Paperclip不显示默认图像的绝对URL

时间:2017-05-23 21:35:10

标签: ruby-on-rails

当我使用Paperclip上传图像时,我可以正确访问完整的URL,如下所示:

user = User.first
user.avatar.url
 => "https://s3.us-east-2.amazonaws.com/mybucket/users/avatars/000/000/001/thumb/data?1494369889"

但是,在调用default_url时,它不会给出绝对路径:

> user2 = User.new
> user2.avatar.url
=> "/users/avatars/missing_thumb.png" 

我的模特:

class User < ApplicationRecord    
  has_attached_file :avatar,
                    styles: { thumb: '100x100>',  square: '200x200#', medium: '300x300>' },
                    default_style: :thumb,
                    default_url: "/users/avatars/missing_:style.png"

我的配置:

  config.paperclip_defaults = {
      s3_host_name: "s3.#{ENV.fetch('AWS_REGION')}.amazonaws.com",
      storage: :s3,
      s3_protocol: :https,
      s3_credentials: {
          s3_host_name: "s3.#{ENV.fetch('AWS_REGION')}.amazonaws.com",
          bucket: ENV.fetch('S3_BUCKET_NAME'),
          access_key_id: ENV.fetch('AWS_ACCESS_KEY_ID'),
          secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY'),
          s3_region: ENV.fetch('AWS_REGION'),
      }
  }   

我做错了什么?

0 个答案:

没有答案