Validate Attachment Content Type Paperclip

后端 未结 4 858
生来不讨喜
生来不讨喜 2021-01-06 03:12

Is it possible to enforce a \'content type\' validation in paperclip without enforcing a \'presence\' validation (i.e. allow blanks)? I currently have:

class         


        
4条回答
  •  春和景丽
    2021-01-06 03:42

    I'm not sure that method is the cause of your failure; Here's my simple class

    class Image < ActiveRecord::Base
      has_attached_file :photo, {
                :styles => { :large => "700x400#", :medium=>"490x368#", :thumbnail=>"75x75#" },
                :default_url => "/images/thumbnail/blank-recipe.png"}
      validates_attachment_content_type :photo, :content_type => /image/ 
    end
    

    Then, if I:

    Image.new.valid?
    #this is true
    

    You might be doing other paperclip validations, though. Can you post a simple example?

提交回复
热议问题