【发布时间】:2016-07-11 01:39:00
【问题描述】:
我有一个使用 carrierwave 和 S3 和 cloudfront 的 rails4 应用程序。我只有后备图像有问题。当我将 html 响应 (<%= image_tag user.profile.avatar.url(:base_thumb), class: "profile-index-avatar" %>) 与助手一起使用时,一切正常,但无法弄清楚如何使其与 json 响应一起使用。
如果我在根页面上查看生产中的 html(由 json 构建),代码是:
第一个 jbuilder:<img src="https://example.com/small_thumb_default.png">
第二个 jbuilder:<img src="https://example.com/assets/small_thumb_default.png">
这些都不起作用。
最重要的是,如果我去用户页面,那么它会尝试获取如下图片:
第一个 jbuilder:<img src="https://example.com/users/small_thumb_default.png">
第二个 jbuilder:<img src="https://example.com/users/assets/small_thumb_default.png">.
我应该改变什么?
jbuilder 第一版
json.array! @other_notifications do |notification|
..
json.profile_image_url notification.sender.profile.avatar.url(:small_thumb)
...
end
jbuilder 第二版
json.array! @other_notifications do |notification|
..
if notification.sender.profile.avatar_url == "default.png"
json.profile_image_url "assets/small_thumb_default.png"
else
json.profile_image_url notification.sender.profile.avatar.url(:small_thumb)
end
...
end
上传者
process :resize_to_fit => [400, 400]
version :base_thumb do
process resize_to_fill: [85, 85]
end
version :small_thumb, :from_version => :base_thumb do
process :resize_to_fill => [40, 40]
end
def default_url
[version_name, "default.png"].compact.join('_')
end
【问题讨论】:
标签: ruby-on-rails json amazon-s3 carrierwave amazon-cloudfront