Validate extension in Paperclip - Ruby on Rails

倖福魔咒の 提交于 2019-11-30 18:53:31

Guess, there is no need to validate it with paperclip's method. You can rather use something like:

has_attached_file :attachment
validates_format_of :attachment_file_name, :with => %r{\.(docx|doc|pdf)$}i

Edit:

Alternatively, to validate it with paperclip:

validates_attachment_content_type :attachment, :content_type => 'text/plain'

^ it will generate content-type mismatch errors automatically.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!