2

我对内容类型进行了此验证:

validates_attachment_content_type :photo, :content_type => /^image\/(jpg|jpeg|pjpeg|png|x-png|gif)$/, :message => 'file type is not allowed (only jpeg/png/gif images)'

我只想显示上面的消息,但它说

 Photos photo content type file type is not allowed (only jpeg/png/gif images)

因为它是照片模型和附件照片。

谢谢

4

3 回答 3

2
> Not a real solution but a Easy one is to skip paperclip validation and
> write custom one
>     validate :check_content_type
>     
>       def check_content_type
>        if !['image/jpeg', 'image/gif','image/png'].include?(self.image_content_type)
>         errors.add_to_base("File '#{self.image_file_name}' is not a valid image type") # or errors.add
>        end
>       end
于 2013-04-19T08:45:29.180 回答
1

我参加这个聚会迟到了。

validates_attachment_size :image, :in => 0.megabytes..2.megabytes,  message: " is too large, try less than 2mb  or for help"

让你:

应该让您离家更近,输出为:

“图像文件太大,请尝试小于 2mb”

于 2015-05-06T18:41:14.160 回答
-3

您好,请 d 验证回形针 avtar 图像

attr_accessible :avatar

has_attached_file :avatar, :styles => { :small => "60x60>", :thumb => "60x60>" }

validates_attachment :avatar, :presence => true, 
:content_type => { :content_type => "image/jpg" }, 
:size => { :in => 0..1000.kilobytes }  
于 2013-04-19T08:56:02.710 回答