7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/devise/orm/couch_potato.rb', line 7
def validates_uniqueness_of(*args)
options = args.
attrib = args.first.to_s
if self.respond_to?("by_#{attrib}")
validate "uniqueness_of_#{attrib}".to_sym
define_method "uniqueness_of_#{attrib}" do
same = self.class.find(:conditions => { attrib => self.send(attrib) })
if same && same.id != self.id
self.errors.add(attrib, options[:message] || :taken)
end
end
else
Rails.logger.warn "WARNING you tried to validate uniqueness of #{attrib} but no view named 'by_#{attrib}' exists. Validation could not be added."
end
end
|