Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我发现 Paperclip 可以验证文件内容类型,即 image/jpeg,但我想专门验证扩展名。这是因为我正在使用一个无法获得一致内容类型的晦涩扩展。任何人都知道这是否可行,或者这样做的好方法?
猜猜,没有必要用回形针的方法来验证它。你可以使用类似的东西:
has_attached_file :attachment validates_format_of :attachment_file_name, :with => %r{\.(docx|doc|pdf)$}i
编辑:
或者,使用回形针对其进行验证:
validates_attachment_content_type :attachment, :content_type => 'text/plain'
^ 它会自动生成内容类型不匹配错误。