# Custom default form builder in Rails 3

**URL:** <https://www.ruby-forum.com/t/custom-default-form-builder-in-rails-3/190590>\
**Category:** Rails\
**Created:** [June 23, 2010, 1:51pm UTC](https://www.ruby-forum.com/t/custom-default-form-builder-in-rails-3/190590 "2010-06-23T13:51:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![regnever](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ba9def/32.png) [@regnever](https://www.ruby-forum.com/u/regnever)\
**Post date:** [June 23, 2010, 1:51pm UTC](https://www.ruby-forum.com/t/custom-default-form-builder-in-rails-3/190590/1 "2010-06-23T13:51:34Z")

</div>

Hello everyone,

I am trying to set a default custom form builder.  
I have defined my form builder class in “lib/mymodule/mybuilder.rb”  
as:

module Mymodule  
class Mybuilder \< ActionView::Helpers::FormBuilder  
…  
end  
end

Then I am trying to use this custom class in application.rb as  
config.action\_view.default\_form\_builder = Mymodule::Mybuilder. But I  
get “Uninitialized constant error.”

Does this mean that my module stored in “lib” directory is not loaded  
automatically?

Thanks in advance,

p.s. I am a newbie to Ruby and Rails as well. I can’t really  
understand the module and class loading process in rails. I will  
appreciate if someone explains me a little bit which folders are  
loaded in initialization process, which I should “require ‘someclass’”  
explicitly.

---

<div class="post-metadata">

**Author:** ![regnever](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ba9def/32.png) [@regnever](https://www.ruby-forum.com/u/regnever)\
**Post date:** [June 23, 2010, 2:58pm UTC](https://www.ruby-forum.com/t/custom-default-form-builder-in-rails-3/190590/2 "2010-06-23T14:58:20Z")

</div>

I gueuss it’s due to the fact your ‘lib/mymodule/mybuilder.rb’ isn’t  
required yet, do this in the config/environment.rb where you have the  
line:

config.action\_view.default\_form\_builder = Mymodule::Mybuilder

C+++

---

<div class="post-metadata">

**Author:** ![regnever](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ba9def/32.png) [@regnever](https://www.ruby-forum.com/u/regnever)\
**Post date:** [June 23, 2010, 3:23pm UTC](https://www.ruby-forum.com/t/custom-default-form-builder-in-rails-3/190590/3 "2010-06-23T15:23:31Z")

</div>

evnironment.rb file doesn’t contain any “config” instance or local  
variable.  
Edge rails documentation (Rails application configuration) suggests  
using:

config.action\_view.default\_form\_builder = MyBuilder

inside application.rb file.

I just cant figure out Where to store my modules/classes in order to  
be able to set that configuration  
int application.rb file.

On Jun 23, 9:57 pm, Christiaan Van den Poel

---

<div class="post-metadata">

**Author:** ![regnever](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ba9def/32.png) [@regnever](https://www.ruby-forum.com/u/regnever)\
**Post date:** [June 24, 2010, 10:28am UTC](https://www.ruby-forum.com/t/custom-default-form-builder-in-rails-3/190590/4 "2010-06-24T10:28:37Z")

</div>

My mistake then, sorry for that.

So when you do a require ‘your/module’ in the application.rb doesn’t  
this  
works?
