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)) 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?