2

I have a validation in my Rails (3.1.4) model to make sure no one tries to upload anything malicious in leiu of their profile image, but when I try to upload a jpeg, the validation is triggering. I'm using the Paperclip gem and I'm unsure if that is having an impact.

validation in user.rb model

validates_attachment_content_type :profile_image, :content_type => ['image/jpeg', 'image/png', 'image/gif'], :message => "Only jpeg, gif and png files are allowed for profile pictures"

When I look at the properties of the jpeg locally (Windows O/S):

  • Item type = JPEG image
  • Type of file: JPEG image (.jpg)

Am I doing something wrong in my validation?

Also, when it triggers, it puts the model and field name before the message. Is there a way to avoid that? ie 'Profile image profile image content type Only jpeg, gif and png files are allowed for profile pictures'

Thank you!

4

1 回答 1

4

您应该添加'image/jpg'到内容类型数组中,我认为这就是您所缺少的。

于 2012-05-24T01:48:34.127 回答