Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails回形针文件类型验证-添加PDF?_Ruby On Rails_Paperclip - Fatal编程技术网

Ruby on rails Rails回形针文件类型验证-添加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

我有只允许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/]
谢谢

试试这个:

 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拿出来)