Setting the default form builder


I implemented a custom form builder called BootstrapFormBuilder. I wanted to use it as the default form builder. I did manage to do that but not without problems. I’d like you to help me understand why my initial approach didn’t work.

I put my class in app/helpers/bootstrap_form_builder.rb. Following the Rails Guide I added:

Rails.application.config.action_view.default_form_builder = BootstrapFormBuilder

to an initializer. Unfortunately form_for was still using the default form builder. I had to change the line above to:

ActionView::Base.default_form_builder = BootstrapFormBuilder

That approach worked. I have two questions:

  1. why didn’t my initial approach work?

  2. if it doesn’t change the default form builder then what does it do?