如果用户没有上传图片,我想显示默认图片。这是我的picture_uploader.rb,我将default.png上传到/ images / fallback。但我无法让它发挥作用。任何提示,我接下来可以尝试什么?
class PictureUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
version :thumb do
process :resize_to_fill => [150, 150]
end
# Provide a default URL as a default if there hasn't been a file uploaded:
def default_url
"/images/fallback/" + [version_name, "default.png"].compact.join('_')
end
end
答案 0 :(得分:2)
根据您的default_url
,您的图片名称应为thumb_default.png
:
[2] pry(main)> version_name = 'thumb'
=> "thumb"
[3] pry(main)> [version_name, "default.png"].compact.join('_')
=> "thumb_default.png"