我不認爲我正確理解這一點,但我如何給用戶一個默認圖像?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