我使用回形针将头像附加到用户身上,效果很好,但当新用户尝试注册时,它会抱怨头像太小且类型不正确。
这就是我验证我的头像的方式:
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
有没有办法让头像变成空白?
我不知道这是否会起作用,但请尝试:
validates_attachment_size :avatar, :less_than => 1.megabytes, :if => avatar_changed?
validates_attachment_content_type :avatar, :content_type => ['image/jpeg', 'image/png', 'image/gif'], :if => avatar_changed?
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)