如何限制Paperclip仅接受图像?
如何限制Paperclip仅接受图像? 如果相关,我正在使用Amazon S3进行存储。 谢谢阅读。
Paperclip具有validation方法,如validates_attachment_presence
, validates_attachment_content_type
和validates_attachment_size
。
所以你需要做的就是传递你想要作为附件的mime类型的图像:
validates_attachment_content_type 'image/png', 'image/jpg'
来自https://makandracards.com/makandra/606-only-allow-pictures-as-paperclip-attachments
validates_attachment_content_type :image, :content_type => /^image\/(jpg|jpeg|pjpeg|png|x-png|gif)$/, :message => 'file type is not allowed (only jpeg/png/gif images)'
- 使用词典重构Ruby on Rails i18n YAML文件
- ActiveRecord查询中“包含”和“连接”之间的区别是什么?
- 登录或注册后如何让Devise重定向到存储位置?
- MiniTest,Capybara,Fixture,Database_Cleaner第二次不通过
- Google地图,Ruby on Rails,使用一个标记缩放级别
- 在rails上使用angularjs和ruby时出现未知的提供程序电子提供程序错误
- Ruby on Rails:无法实现星级评分系统
- 在Rails中的Mailboxer收件箱中显示用户名
- Rails rspec undefined方法`receive_message’用于#<RSpec :: ExampleGroups ::