Paperclip Validations and STI

A Rails application we’ve been working on uses Paperclip to make managing file attachments easy to deal with. We’re using Single Table Inheritance (STI) to store all the different assets in a single table. In one of the subclasses I want to restrict the content type to only PDFs. Sounds like it should be simple, right? Unfortunately, the way Paperclip is currently written means that it shares all the validation definitions with all the related subclasses. (You can see the bug on Github)

The workaround for us is pretty simple though, all we do is set a condition on the validation to only check if the object is the one we expect.

class Document < Asset
  validates_attachment_content_type :asset, :content_type => ['application/pdf','application/x-pdf'], :if => Proc.new { |d| d.kind_of?(Document)}
end