开发者

Paperclip question update/change image

Excuse me I am using paperclip. so when i attachment a file diferent to image (when i don´t upload jpeg,gif or png example zip) show this error:

* Photo C:/Users/MAXIMI~1/AppData/Local/Temp/stream4556-0.rar is not recognized by the 'identify' command.
* Photo C:/Users/MAXIMI~1/AppData/Local/Temp/stream4556-0.rar is not recognized by the 'identify' command.
* Photo C:/Users/MAXIMI~1/AppData/Local/Temp/stream4556-0.rar is not recognized by the 'identify' command.

which is the locale tree path for this error? or which ar开发者_JAVA百科e the locale tree path for paperclip error.

NOTE: I am talking about i18n locale (translate)

thanks in advance


I don't know about the i18n translation path for this, but if you don't want users to upload non-image file types you should use the validates_attachment_content_type validator that paperclip gives you:

validates_attachment_content_type :attachment, /^image.*/, :message => "Your error message"

Which will generate a sane error for the user instead of the cryptic ImageMagick one. Alternatively, if you want users to be able to upload any file type, but style images a certain way, you can fix your problem like this:

has_attached_file :attachment, :styles => {:thumbnail => ["89x67!", :jpg]}
before_post_process :image?

def image?
  !!(attachment_content_type =~ /^image.*/)
end

This will make it so that all images that get uploaded will also generate an 89x67 sized thumbnail, but if it's not an image type it will skip the processing because image? will return false, and the post_process will not execute (but the file will still be uploaded).

This adds the benefit of being able to say asset.image? later on in a view or something and deciding whether to render it within an image_tag, or as a direct link (just for example).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜