From 28768e371331893781c2463fd864450c2f59ff90 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20Rodr=C3=ADguez=20Troiti=C3=B1o?=
Date: Mon, 15 Mar 2010 19:11:46 +0100
Subject: [PATCH] Recovers error_messages for ActiveRecordInstanceTag.
---
.../lib/action_view/helpers/active_model_helper.rb | 4 ++++
.../test/template/active_model_helper_test.rb | 14 ++++++++++++++
2 files changed, 18 insertions(+), 0 deletions(-)
diff --git a/actionpack/lib/action_view/helpers/active_model_helper.rb b/actionpack/lib/action_view/helpers/active_model_helper.rb
index e3db292..bbe8609 100644
--- a/actionpack/lib/action_view/helpers/active_model_helper.rb
+++ b/actionpack/lib/action_view/helpers/active_model_helper.rb
@@ -295,6 +295,10 @@ module ActionView
end
end
+ def error_message
+ object.errors[@method_name]
+ end
+
def column_type
object.send(:column_for_attribute, @method_name).type
end
diff --git a/actionpack/test/template/active_model_helper_test.rb b/actionpack/test/template/active_model_helper_test.rb
index 371aa53..71c7d5b 100644
--- a/actionpack/test/template/active_model_helper_test.rb
+++ b/actionpack/test/template/active_model_helper_test.rb
@@ -147,6 +147,20 @@ class ActiveModelHelperTest < ActionView::TestCase
)
end
+ def test_field_error_proc
+ old_proc = ActionView::Base.field_error_proc
+ ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
+ %(#{html_tag} #{[instance.error_message].join(', ')}
).html_safe
+ end
+
+ assert_dom_equal(
+ %( can't be empty
),
+ text_field("post", "author_name")
+ )
+ ensure
+ ActionView::Base.field_error_proc = old_proc if old_proc
+ end
+
def test_form_with_string
assert_dom_equal(
%(
),
--
1.6.4.4