From 11497efbcbc552aa520f9c305f2c729c965d9def Mon Sep 17 00:00:00 2001 From: David Trasbo Date: Mon, 12 Apr 2010 13:23:40 +0200 Subject: [PATCH] Make ActiveModel::Errors#to_xml specify which attribute each error belongs to --- activemodel/lib/active_model/errors.rb | 2 +- activemodel/test/cases/validations_test.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb index e6c86c7..27e9e94 100644 --- a/activemodel/lib/active_model/errors.rb +++ b/activemodel/lib/active_model/errors.rb @@ -166,7 +166,7 @@ module ActiveModel options[:builder].instruct! unless options.delete(:skip_instruct) options[:builder].errors do |e| - to_a.each { |error| e.error(error) } + full_messages.each_with_index { |error, index| e.error(error, :on => keys[index]) } end end diff --git a/activemodel/test/cases/validations_test.rb b/activemodel/test/cases/validations_test.rb index 925a68d..ec7f801 100644 --- a/activemodel/test/cases/validations_test.rb +++ b/activemodel/test/cases/validations_test.rb @@ -147,8 +147,8 @@ class ValidationsTest < ActiveModel::TestCase assert !r.valid? xml = r.errors.to_xml(:skip_instruct => true) assert_equal "", xml.first(8) - assert xml.include?("Title is Wrong Create") - assert xml.include?("Content Empty") + assert xml.include?('Title is Wrong Create') + assert xml.include?('Content Empty') end def test_validation_order -- 1.7.0.3