From 160cb3126ee79183c7a9f710075a376934b1ec10 Mon Sep 17 00:00:00 2001 From: Iain Hecker Date: Sun, 24 Aug 2008 12:42:37 +0200 Subject: [PATCH] Form label uses i18n --- actionpack/lib/action_view/helpers/form_helper.rb | 7 ++++++- actionpack/test/template/form_helper_i18n_test.rb | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletions(-) create mode 100644 actionpack/test/template/form_helper_i18n_test.rb diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 7bb82ba..35ebaec 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -545,7 +545,12 @@ module ActionView add_default_name_and_id(name_and_id) options.delete("index") options["for"] ||= name_and_id["id"] - content = (text.blank? ? nil : text.to_s) || method_name.humanize + if text.blank? + content = object.class.respond_to?(:human_attribute_name) ? object.class.human_attribute_name(method_name) : method_name.humanize + else + content = text.to_s + end + #content = (text.blank? ? nil : text.to_s) || object_name.classify.constantize.human_attribute_name(method_name) label_tag(name_and_id["id"], content, options) end diff --git a/actionpack/test/template/form_helper_i18n_test.rb b/actionpack/test/template/form_helper_i18n_test.rb new file mode 100644 index 0000000..2e74feb --- /dev/null +++ b/actionpack/test/template/form_helper_i18n_test.rb @@ -0,0 +1,19 @@ +require 'abstract_unit' +require 'active_record_unit' + +class FormHelperI18nTest < ActionView::TestCase + tests ActionView::Helpers::FormHelper + + uses_mocha 'form_helper_i18n_test' do + + def test_form_for_with_translated_labels + Reply.stubs(:human_attribute_name).with('title').returns("translated title") + fields_for(Reply.new) do |f| + @string = f.label(:title) + end + assert_equal "", @string + end + + end + +end -- 1.5.4.3