1

I have a Rails 4 app using Paperclip 4.3.2. I have the following specified in my model:

    validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/, :message => "some message"

When I try to load a wrong file I hoped to find the message "some message" but I get the message:

Avatar translation missing: ca.activerecord.errors.models..attributes.avatar.spoofed_media_type

Any idea what's going wrong here?

Toby Speight
  • 27,591
  • 48
  • 66
  • 103
Rafa
  • 11
  • 1

1 Answers1

2
validates_attachment :avatar,
  content_type: { content_type: /\Aimage\/.*\Z/, message: "Some Message" }

Good ref


To give you some context as to the Avatar translation missing error - this is typically caused by a lack of I18n translations...

# config/locales/[[lang]].yml
ca:
  activerecord:
    errors:
      models:
         attributes:
           spoofed_media_type: "Message"

This should give you some insight.


Finally, "spoofed media type" errors often mean you don't have the file (or equivalent) on your system. I can only speak from Windows experience; you need to set file up separately if you don't have DevKit installed.

Community
  • 1
  • 1
Richard Peck
  • 76,116
  • 9
  • 93
  • 147
  • Thanks Rich for your answer, but I'm trying to be DRY with locale's entries. My application has about 90 models that have attachment :avatar. With this solution I must create a locale entry for each one of them. I would like a single message to all application validates_attachment_content_type. So I'm trying to force the message on validates_attachment_content_type but paperclip always search the message error in locale key activerecord.errors..attributes.spoofed_media_type. – Rafa Jan 26 '16 at 13:30
  • Why don't you just have a central "asset" model? We used the reference [here](http://rails-bestpractices.com/posts/2010/08/18/use-sti-and-polymorphic-model-for-multiple-uploads/) and have 1 `asset` model storing all our attachments: http://i.imgur.com/fVX850Y.png – Richard Peck Jan 26 '16 at 13:33