在 redemption_image.rb 中,
class RedemptionImage < ActiveRecord::Base
belongs_to :business, :touch => true
has_attached_file :display_image, :url => "/system/:class/:attachment/:id_partition/:hash.:extension",
:hash_secret => "redemptionimagesqqqa"
validates_attachment :display_image, :content_type => { :content_type => /\Aimage/ }, :size => { :in => 0..300.kilobytes,
:message => "must be lesser than 300 KB. Image height and width must be lesser than 500 px." }
对 display_image 的大小、content_type 和存在进行了验证。它会显示两次消息:保存兑换图像时出错:显示图像文件大小必须小于 300 KB。图片高度和宽度必须小于 500 像素,显示图片必须小于 300 KB。图片高度和宽度必须小于 500 像素。
如果没有提供自定义消息,则如图所示两次闪烁错误