lib/ripple/validations/associated_validator.rb in ripple-0.8.1 vs lib/ripple/validations/associated_validator.rb in ripple-0.8.2
- old
+ new
@@ -18,12 +18,11 @@
module Ripple
module Validations
class AssociatedValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
- unless Array(value).map {|r| r.nil? || r.valid? }.all?
- record.errors.add(attribute, :invalid, :default => options[:message], :value => value)
- end
+ return if (value.is_a?(Array) ? value : [value]).collect{ |r| r.nil? || r.valid? }.all?
+ record.errors.add(attribute, :invalid, options.merge(:value => value))
end
end
module ClassMethods
def validates_associated(*attr_names)