我认为我没有正确理解这一点,但是我如何为用户提供默认图像?
def default_url
"/images/fallback/" + [version_name, "default.png"].compact.join('_')
end
我的图像/备用目录中有一个名为“default.png”的图像。我在网上也看到人们将 version_name 更改为“tiny”之类的东西,但这似乎对我也不起作用。这是怎么回事?版本名称到底是什么?
我试过类似的东西
def default_url
"/images/fallback/default.png"
end
但这也不起作用。我有什么误解?谢谢!
编辑:
class ImageUploader < CarrierWave::Uploader::Base
# Include RMagick or MiniMagick support:
include CarrierWave::RMagick
storage :file
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
# Provide a default URL as a default if there hasn't been a file uploaded:
def default_url
???????
end
# Create different versions of your uploaded files:
version :thumb do
process :resize_to_fill => [80, 80]
end
end
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :name, :email, :password, :password_confirmation,
:remember_me, :image, :remote_image_url, :image_cache
mount_uploader :image, ImageUploader
end