Ruby on rails Rails回形针文件类型验证-添加PDF?
我有只允许png和jpg的验证设置,但我也想允许PDF。我似乎不知道如何将该语法添加到现有代码中Ruby on rails Rails回形针文件类型验证-添加PDF?,ruby-on-rails,paperclip,Ruby On Rails,Paperclip,我有只允许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, :matc
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/]
谢谢 试试这个:
validates_attachment_content_type :attachment, :content_type => ['image/jpeg', 'image/png', 'application/pdf']
试试这个:
validates_attachment_content_type :attachment, :content_type => ['image/jpeg', 'image/png', 'application/pdf']
这是我为一个类似项目编写的代码
validates_attachment_content_type :attachment, content_type: ['image/jpeg', 'image/png', 'image/gif', 'application/pdf']
(显然你会把gif拿出来)这是我为一个类似项目编写的代码
validates_attachment_content_type :attachment, content_type: ['image/jpeg', 'image/png', 'image/gif', 'application/pdf']
(显然你会把gif拿出来)