这是我在模型中使用 paperclip 的方法:
has_attached_file :photo,
styles: {
display: {
geometry: "146x153#",
format: :jpg,
},
message: {
geometry: "48x48#",
format: :jpg,
}
}
validates_attachment_content_type :photo, content_type: ['image/jpeg', 'image/png','image/gif']
validates_attachment_size :photo, less_than: 2.megabytes, unless: :record_is_new?
目前程序可以正常运行,但我希望可以选择上传图片,即如果用户不想上传图片,则不需要进行验证。