我使用回形針將頭像附加到用戶上,這種方式很好,但是當新用戶嘗試註冊時,它抱怨頭像太小而不是正確的類型。在欄杆中設置欄位可選
這是我如何驗證我的頭像:
validates_attachment_size :avatar, :less_than => 1.megabytes
validates_attachment_content_type :avatar, :content_type => ['image/jpeg', 'image/png', 'image/gif']
這是錯誤我得到當我嘗試註冊。
There were problems with the following fields:
* Avatar file size file size must be between 0 and 1048576 bytes.
* Avatar content type is not included in the list
是否有無論如何使頭像可以是空白?
我用 「:除非=>:new_user?」並寫了一個函數返回true/false似乎已經修復它 – Arcath 2009-12-24 12:32:38
:if => avatar_file_name_changed?爲我工作 – 2011-08-17 07:20:40