Mat
Mat

Reputation: 1011

Rails : Paperclip MissingRequiredValidatorError

I have a polymorphic resource in my rails app :

class Media < ActiveRecord::Base
  # some stuff
  belongs_to :mediable, :polymorphic => true
  # some stuff

  class Media::TeaserCroppedImage < Media
   has_attached_file :attachment,
                :styles                => ...,
                :processors            => ...,
                :path                  => "...",
                :url                   => "...",
                # ...

   validates_attachment :attachment, matches: { file_name: ["image/jpeg", "image/jpg"] }

As you can see, I tried to add the paperclip validator. But apparently, it doesn't work, and I still get the error MissingRequiredValidatorError.

Is there a problem with the syntax of the validator ?

Upvotes: 1

Views: 432

Answers (1)

K M Rakibul Islam
K M Rakibul Islam

Reputation: 34318

You have to have to include a content_type validation, something like this:

validates_attachment_content_type :attachment, :content_type => ["image/jpg", "image/jpeg"]

or you can replace your current validation with this:

validates_attachment_file_name :attachment, :matches => [/jpe?g\Z/]

Upvotes: 1

Related Questions