From 84b8537cb669033636ee0d502a501f082cbfff1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Pie=C5=84kowski?= Date: Sat, 4 Oct 2025 14:31:10 +0200 Subject: [PATCH 1/2] Handle boolean options in `fields_for` --- demo/app/models/address.rb | 2 ++ lib/bootstrap_form/form_builder.rb | 2 +- test/bootstrap_fields_for_test.rb | 22 ++++++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/demo/app/models/address.rb b/demo/app/models/address.rb index 89b92b41b..003db314a 100644 --- a/demo/app/models/address.rb +++ b/demo/app/models/address.rb @@ -1,3 +1,5 @@ class Address < ApplicationRecord belongs_to :user + + validates :city, presence: true end diff --git a/lib/bootstrap_form/form_builder.rb b/lib/bootstrap_form/form_builder.rb index c4b425479..aac1bf367 100644 --- a/lib/bootstrap_form/form_builder.rb +++ b/lib/bootstrap_form/form_builder.rb @@ -90,7 +90,7 @@ def fields_for_options(record_object, fields_options) field_options = fields_options field_options = record_object if record_object.is_a?(Hash) && record_object.extractable_options? %i[layout control_col inline_errors label_errors].each do |option| - field_options[option] ||= options[option] + field_options[option] = field_options.key?(option) ? field_options[option] : options[option] end field_options[:label_col] = field_options[:label_col].present? ? field_options[:label_col].to_s : options[:label_col] field_options diff --git a/test/bootstrap_fields_for_test.rb b/test/bootstrap_fields_for_test.rb index 4dc072dc0..9e9e8ea50 100644 --- a/test/bootstrap_fields_for_test.rb +++ b/test/bootstrap_fields_for_test.rb @@ -25,6 +25,28 @@ class BootstrapFieldsForTest < ActionView::TestCase assert_equivalent_html expected, output end + test "bootstrap_fields_for helper works with boolean options" do + @user.address = Address.new + @user.valid? + + output = bootstrap_form_for(@user, inline_errors: true) do |_f| + bootstrap_fields_for :address, @user.address, inline_errors: false do |af| + af.text_field(:city) + end + end + + expected = <<~HTML +
+
+ + + +
+
+ HTML + assert_equivalent_html expected, output + end + test "bootstrap_fields_for helper works for serialized hash attributes" do @user.preferences = { "favorite_color" => "cerulean" } From 64023bfcd89da98d6ede8fff1ccff257ea4b0cf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Pie=C5=84kowski?= Date: Sat, 4 Oct 2025 14:32:05 +0200 Subject: [PATCH 2/2] Fix Rubocop offenses --- demo/app/models/model_user.rb | 1 + gemfiles/8.0.gemfile | 2 +- gemfiles/edge.gemfile | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/demo/app/models/model_user.rb b/demo/app/models/model_user.rb index 46a2ab015..654ec7135 100644 --- a/demo/app/models/model_user.rb +++ b/demo/app/models/model_user.rb @@ -1,5 +1,6 @@ class ModelUser include ActiveModel::Model + attr_accessor :email, :password, :comments, :misc validates :email, :password, presence: true diff --git a/gemfiles/8.0.gemfile b/gemfiles/8.0.gemfile index c25dfc7ef..9e8686ae5 100644 --- a/gemfiles/8.0.gemfile +++ b/gemfiles/8.0.gemfile @@ -4,6 +4,6 @@ eval File.read(gems), binding, gems # rubocop: disable Security/Eval gem "bigdecimal" if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") gem "drb" if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") gem "mutex_m" if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") -gem "rails", "~> 8.0.1" gem "propshaft" +gem "rails", "~> 8.0.1" gem "sqlite3" diff --git a/gemfiles/edge.gemfile b/gemfiles/edge.gemfile index 62ef2e13b..e0e3f56e3 100644 --- a/gemfiles/edge.gemfile +++ b/gemfiles/edge.gemfile @@ -4,6 +4,6 @@ eval File.read(gems), binding, gems # rubocop: disable Security/Eval gem "bigdecimal" if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") gem "drb" if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") gem "mutex_m" if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.4.0") -gem "rails", git: "https://github.com/rails/rails.git", branch: "main" gem "propshaft" +gem "rails", git: "https://github.com/rails/rails.git", branch: "main" gem "sqlite3"