yellowreign
yellowreign

Reputation: 3638

Rails validation on content type not working with Paperclip

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):

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!

Upvotes: 2

Views: 2295

Answers (1)

David
David

Reputation: 7303

You should add 'image/jpg' to the content type array, I think that's what you're missing.

Upvotes: 4

Related Questions