From 6935683840f6ddd909638a3dc6e0a4bde4019b20 Mon Sep 17 00:00:00 2001 From: Alexander Tipugin Date: Wed, 24 Sep 2014 00:54:36 +0400 Subject: [PATCH 1/2] Try to use localized attribute name for label errors --- lib/bootstrap_form/form_builder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bootstrap_form/form_builder.rb b/lib/bootstrap_form/form_builder.rb index a2c02c747..8426ce8bd 100644 --- a/lib/bootstrap_form/form_builder.rb +++ b/lib/bootstrap_form/form_builder.rb @@ -307,7 +307,7 @@ def generate_label(id, name, options, custom_label_col, group_layout) if label_errors && has_error?(name) error_messages = get_error_messages(name) - label_text = (options[:text] || name.to_s.humanize).to_s.concat(" #{error_messages}") + label_text = (options[:text] || object.class.human_attribute_name(name)).to_s.concat(" #{error_messages}") label(name, label_text, options.except(:text)) else label(name, options[:text], options.except(:text)) From 6479d18c0f9207456e8648277daa33a44ec0f461 Mon Sep 17 00:00:00 2001 From: Alexander Tipugin Date: Thu, 9 Oct 2014 10:31:28 +0400 Subject: [PATCH 2/2] Test that labels with errors uses #human_attribute_name under the hood --- test/bootstrap_form_test.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/bootstrap_form_test.rb b/test/bootstrap_form_test.rb index b8c6287bf..d2f7a64f1 100644 --- a/test/bootstrap_form_test.rb +++ b/test/bootstrap_form_test.rb @@ -63,6 +63,18 @@ def setup assert_equal expected, bootstrap_form_for(@user, label_errors: true, inline_errors: true) { |f| f.text_field :email } end + test "label error messages use humanized attribute names" do + I18n.backend.store_translations(:en, {activerecord: {attributes: {user: {email: 'Your e-mail address'}}}}) + + @user.email = nil + @user.valid? + + expected = %{
can't be blank, is too short (minimum is 5 characters)
} + assert_equal expected, bootstrap_form_for(@user, label_errors: true, inline_errors: true) { |f| f.text_field :email } + + I18n.backend.store_translations(:en, {activerecord: {attributes: {user: {email: nil}}}}) + end + test "alert message is wrapped correctly" do @user.email = nil @user.valid?