validates :width, :presence => true, :numericality => true, :natural_number => true
validates :height, :presence => true, :numericality => true, :natural_number => true
validates :filesize, :presence => true, :numericality => {:greater_than => 0, :less_than_or_equal_to => 2000000}, :natural_number => true
- validates :artist_id, :presence => true, :numericality => true, :existence => true
+ validates :artist_id, :presence => true, :numericality => true, :existence => {:both => false}
validates :md5, :presence => true, :length => {:minimum => 32, :maximum => 32}
before_destroy :destroy_with_file
end
def visible? ar
+ return true if ar.is_a?(Admin)
self.own?(ar)
end
def store(imager)
unless imager
- self.errors.add :base, 'illegal picture data'
+ self.errors.add :base, I18n.t('errors.invalid_image')
return false
end
res = false
self.attributes = {:ext => imager.ext, :width => imager.width, :height => imager.height, :filesize => imager.filesize, :md5 => imager.md5}
OriginalPicture.transaction do
if res = self.save
- if res = PictureIO.original_picture_io.put(imager.binary, self.filename)
- res = true
- else
- self.errors.add :base, 'original picture io does not work'
+ begin
+ res = PictureIO.original_picture_io.put(imager.binary, self.filename)
+ rescue PictureIO::Error
+ res = false
+ self.errors.add :base, I18n.t('picture_io.error')
raise ActiveRecord::Rollback
end
end