diff --git a/lib/bootstrap_form/form_group_builder.rb b/lib/bootstrap_form/form_group_builder.rb index 620433da..94ec6dab 100644 --- a/lib/bootstrap_form/form_group_builder.rb +++ b/lib/bootstrap_form/form_group_builder.rb @@ -107,7 +107,7 @@ def form_group_css_options(method, html_options, options) end def form_group_placeholder(options, method) - form_group_label_text(options[:label]) || object.class.human_attribute_name(method) + form_group_label_text(options[:label]) || (object && object.class.human_attribute_name(method)) || method.to_s.humanize # rubocop:disable Style/SafeNavigation end end end diff --git a/test/bootstrap_form_group_test.rb b/test/bootstrap_form_group_test.rb index 5f15035e..acc9d102 100644 --- a/test/bootstrap_form_group_test.rb +++ b/test/bootstrap_form_group_test.rb @@ -118,6 +118,16 @@ class BootstrapFormGroupTest < ActionView::TestCase assert_equivalent_html expected, @builder.text_field(:email, label_as_placeholder: true) end + test "label as placeholder with form_with" do + expected = <<~HTML +