From c8c36d2848937f75fa2523a3747874798094b69b Mon Sep 17 00:00:00 2001 From: Andrew Coleman Date: Sat, 21 Mar 2009 21:31:52 -0500 Subject: [PATCH] pre-exist validations that work for duplicate file names --- app/models/photo.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/models/photo.rb b/app/models/photo.rb index eb495c9..16342f9 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -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