LoginSignup
1
1

More than 5 years have passed since last update.

Paperclipでcontent_typeのバリデーションをしたくない

Last updated at Posted at 2015-10-06

参考: https://github.com/thoughtbot/paperclip/issues/1740

Problem

Paperclipでどんな種類のファイルでもアップロードできるようにしたいので、content_typeのバリデーションを指定したくない

Solution

  • validate_media_typefalseにする
  • do_not_validate_attachment_file_typeを指定する
class Asset < ActiveRecord::Base
  include Paperclip::Glue

  has_attached_file :asset,
    :validate_media_type => false

  validates_attachment :asset, :presence => true,
    :size => { :in => 0..10.megabytes }

  do_not_validate_attachment_file_type :asset
end
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1