我的验证设置仅允许png和jpg,但我还想允许PDF。我似乎无法弄清楚如何将该语法添加到现有代码中。
has_attached_file :receipt
# Validate content type
validates_attachment_content_type :receipt, :content_type => /\Aimage/
# Validate filename
validates_attachment_file_name :receipt, :matches => [/png\Z/, /jpe?g\Z/]
谢谢!
答案 0 :(得分:17)
这就是我在代码中的类似项目......
validates_attachment_content_type :attachment, content_type: ['image/jpeg', 'image/png', 'image/gif', 'application/pdf']
(显然你会把gif拿出来)
答案 1 :(得分:3)
试试这个:
validates_attachment_content_type :attachment, :content_type => ['image/jpeg', 'image/png', 'application/pdf']