lib/cieloz/helpers.rb in cieloz-0.0.17 vs lib/cieloz/helpers.rb in cieloz-0.0.18
- old
+ new
@@ -27,9 +27,21 @@
attrs.count == 1 ? attrs.first : attrs
end
end
module InstanceMethods
+ def add_error(attr, message)
+ error_message = errors.add(attr, message).first
+ if @source
+ source_attr = @opts[attr]
+ if source_attr.is_a?(Symbol) and @source.respond_to?(source_attr)
+ @source.errors.add source_attr, error_message
+ else
+ @source.errors.add :base, "#{attr}: #{error_message}"
+ end
+ end
+ end
+
def valid?
valid = _valid?
unless @source.nil?
unless valid
errors.messages.each { |attr,attr_errors|