carrierwave
をS3
とcloudfront
としたrails4アプリがあります。私は、代替画像にのみ問題があります。私がhtml
のレスポンス(<%= image_tag user.profile.avatar.url(:base_thumb), class: "profile-index-avatar" %>
)をヘルパーで使用していると、すべて正常に動作しますが、それをどのようにしてjson
応答で動作させるのか理解できません。rails carrierwave + S3 + json response
私はルート・ページ上の生産に(JSONから構築された)HTMLをチェックアウトする場合のコードは次のとおりです。
第一のJBuilder:<img src="https://example.com/small_thumb_default.png">
2STの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