我不认为我正确理解这一点,但我如何给用户一个默认图像?rails carrierwave default_url不工作
def default_url
"/images/fallback/" + [version_name, "default.png"].compact.join('_')
end
我在我的images/fallback目录中有一个名为'default.png'的图像。在线上看到人们也会将version_name更改为“微小”之类的东西,但这对我来说似乎也不起作用。这是怎么回事?版本名称究竟是什么?
我想是这样
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
哪一个我可以参考呢?我仍然有点困惑。我认为default_url是我参考默认图像的地方,而不是拇指的任何地方。我应该把默认图像放在其他地方吗? 即时通讯从我的版本使用的图像:拇指,并试图thumb_path,但我不认为这是正确的.. – Sasha 2012-04-11 06:08:22
@Crystal默认图像使用时,请求的图像无法找到。例如,你删除small_thumb,比carrierwave要显示small_thumb_default.png。如果您确定所有图像始终就位,则可以避免使用默认图像。 – 2012-04-11 06:14:33
嗯,它仍然不太工作。即时通讯有一个注册注册表单,并且当用户注册时,我希望显示默认图像,至少在用户改变它之前。我注册后,我检查我的数据库,我的'图像'列仍然为空。如果我手动将我的个人资料图片更改为图片,那么'图片'列会获取数据。有没有办法在用户首次注册时在'image'列中基本拥有'default.png'数据? – Sasha 2012-04-11 06:27:22