我有一个使用carrierwave
和S3
和cloudfront
的rails4应用程序。我只有后备图像的问题。当我使用html
响应(<%= image_tag user.profile.avatar.url(:base_thumb), class: "profile-index-avatar" %>
)与助手一切正常,但无法弄清楚如何使它与json
响应。rails carrierwave + S3 + json响应
如果我检查了生产中的HTML(从JSON建)根页上的代码是:
1日的JBuilder:<img src="https://example.com/small_thumb_default.png">
2ST的JBuilder:<img src="https://example.com/assets/small_thumb_default.png">
这些都不是工作。
在此之上,如果我去,让我们给用户的网页说,然后它会尝试获取照片喜欢:
1日的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