gpt4 book ai didi

ruby-on-rails - Rails 4,Heroku 上的回形针无法识别损坏的图像

转载 作者:行者123 更新时间:2023-12-04 06:01:50 25 4
gpt4 key购买 nike

无法解决我项目中的图片问题。

总结:使用 Paerclip 和 S3 托管在 Heroku 上的 Rilas 4

问题开始于必须在 S3 中使用以前使用的自定义上传逻辑。图片网址看起来像这样 /profile_picture/:style_:image_hash .它适用于存在的图像但不存在的图像回形针仍在尝试访问不存在的图像并且实际链接看起来像这样:http://s3.amazonaws.com/project/profile_pictures/100h_ .

 has_attached_file :picture,
styles: { :'53h' => '', :'100h' => '' },
convert_options: {
:'100h' => '-gravity center -thumbnail 165x165^ -extent 165x165',
:'53h' => '-gravity center -thumbnail 45x45^ -extent 45x45'
},
path: 'profile_pictures/:style_:filename',
default_url: '/images/default-pp-large.jpg'

我猜这可能是因为实际文件名中的样式,但我不确定,以另一种方式 defauly_url不工作,图像全部损坏,不包括实际存在的图像。

你能帮忙吗?

最佳答案

最后,我为回形针 gem 做了一个猴子补丁。将此行添加到 config/initializers/paperclip.rb

module Paperclip
class Attachment
alias_method :original_url, :url

def url(style_name = default_style, options = {})
if @instance.public_send("#{@name.to_s}_file_name").blank?
'default-pp-large.jpg'
else
original_url(style_name, options)
end
end
end
end

关于ruby-on-rails - Rails 4,Heroku 上的回形针无法识别损坏的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32589254/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com