在我的项目中,我没有使用表单来发送图像。我是从path得到的。
如何仅使用path保存图像?
我有这个型号
class Picture
include Mongoid::Document
include Mongoid::Paperclip
has_mongoid_attached_file :avatar
end我试过了(在mysql的回形针中,这是可行的)
p = Picture.new
p.avatar = File.open('/path/to/my/image.jpg')
p.save如果我这样做,我会收到一个错误。
Paperclip::Errors::MissingRequiredValidatorError: Paperclip::Errors::MissingRequiredValidatorError
我该怎么做呢?
谢谢!
发布于 2017-09-24 09:02:06
我忘记了验证:
validates_attachment_content_type :avatar,
:content_type => ["image/jpg", "image/jpeg", "image/png", "image/gif"]这会解决这个问题。
https://stackoverflow.com/questions/46385504
复制相似问题