pre-exist validations that work for duplicate file names

master
Andrew Coleman 2009-03-21 21:31:52 -05:00
parent 1a12aa9798
commit c8c36d2848
1 changed files with 3 additions and 1 deletions

View File

@ -2,7 +2,6 @@ class Photo < ActiveRecord::Base
attr_accessor :file
validates_presence_of :author_id, :album_id
validates_uniqueness_of :filename, :scope => :album_id
belongs_to :album
belongs_to :author
@ -65,6 +64,9 @@ class Photo < ActiveRecord::Base
if self.file[:size] > 3 * 1048576
self.errors.add(:file, 'File is too big (3MB max)')
end
if self.album.photos.count(:conditions => { :filename => self.file[:filename] }) > 0
self.errors.add(:file, 'already seems to exist in this album')
end
return false unless self.errors.empty?
begin