Skip to content

Conversation

pienkowb
Copy link

@pienkowb pienkowb commented Oct 4, 2025

This PR fixes how boolean options (e.g. inline_errors) are handled in the fields_for helper.

Currently, option defaults are loaded in the helper using the following code:

%i[layout control_col inline_errors label_errors].each do |option|
  field_options[option] ||= options[option]
end

This approach doesn't work for boolean options, because false evalues as falsy, even though it's a legitimate value. As a result, the option value is being overriden with a default value.

For example, the code below does not work as indended (inline errors are still added to the City field):

bootstrap_form_for @user, inline_errors: true do |f|
  f.fields_for :address, inline_errors: false do |af|
    af.text_field :city
  end
end

In order to fix this, I changed:

field_options[option] ||= options[option]

to:

field_options[option] = field_options.key?(option) ? field_options[option] : options[option]

which is more verbose, but works corrently for boolean options.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant