Custom form builder uninitialized constant

I am trying to build a custom form builder and have looked at the rails guides and other blog posts about doing this. I’ve created an empty builder and reference it from my template expecting no errors since I had not overridden any of the FormBuilder methods, but am getting the following error:

ActionView::Template::Error (uninitialized constant #<Class:0x00007fb774eb16c0>::MyFormBuilder)

Nowhere in the rails guides (api.rubyonrails.org/v6.0.3.4/…/FormBuilder.html ) is it mentioned where to put my custom builder or how to get it recognized. The articles and blog posts that I’ve found either don’t mention it or suggest a number of different ways of going about having it accessible, including putting a require at the top of my template file, which doesn’t sound like best practice.

Any help would be appreciated, and it would be great if the docs were a bit more explicit on how to succeed at having a custom builder loaded.


-----template file---------
<%= fields_for page, builder: MyFormBuilder do |p| %> 
blah, blah
<% end %>
------------ 
# app/helpers/first_app_builder.rb

class MyFormBuilder <ActionView::Helpers::FormBuilder
end

Answer: I had changed the name of the builder and didn’t change the name of the file so it didn’t get properly loaded / found.

Once the name was corrected to match the filename I was able to put the custom builder in config/initializers, app/helpers, or a custom app/builders/ directory and it worked fine.

I still believe that it would be helpful if the guide or api docs gave an explicit best practice, or couple of examples of where a reasonable place to store the file would be.

-Hawley