# Problem with Custom Form Builder

**URL:** <https://www.ruby-forum.com/t/problem-with-custom-form-builder/169176>\
**Category:** Rails\
**Created:** [May 30, 2009, 8:28pm UTC](https://www.ruby-forum.com/t/problem-with-custom-form-builder/169176 "2009-05-30T20:28:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![satynos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9bcb4/32.png) [@satynos](https://www.ruby-forum.com/u/satynos)\
**Post date:** [May 30, 2009, 8:28pm UTC](https://www.ruby-forum.com/t/problem-with-custom-form-builder/169176/1 "2009-05-30T20:28:51Z")

</div>

I created my custom form builder (which inherits rails built-in form  
builder) name spaced under my app module. I also assigned this form  
builder to be the default action view form builder in the  
environment.rb. When I am starting the server, rails is throwing  
different errors some times saying unexpected kDEF expecting “\<” or “\n”  
or “;” or some times saying unxpected $end expecting “\<” or “\n” or “;”

Following is the implementation of my code.

lib/my\_app.rb  
module MyApp  
VERSION = 1  
end

lib/my\_app/form\_builder.rb  
require ‘my\_app’  
module MyApp  
class FormBuilder \< ActionView::Helpers::FormBuilder  
include MyApp::FormHelper  
end #end of class  
end #end of module

lib/my\_app/form\_helper.rb  
require ‘my\_app’  
module MyApp  
module FormHelper \< ActionView::Helpers::FormHelper  
end #end of module FormHelper  
end #end of module MyApp

and at the end of environment.rb (after initializer)  
ActionView::Base.default\_form\_builder = MyApp::FormBuilder

Why is Rails not accepting my FormBuilder when I nest it under MyApp  
module?

Btw: If I declare the FormBuilder as a standalone class, its working.

Thanks in advance.  
-Satynos

---

<div class="post-metadata">

**Author:** ![satynos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9bcb4/32.png) [@satynos](https://www.ruby-forum.com/u/satynos)\
**Post date:** [May 30, 2009, 9:42pm UTC](https://www.ruby-forum.com/t/problem-with-custom-form-builder/169176/2 "2009-05-30T21:42:37Z")

</div>

Any help is much appreciated. This insight will help me not just for  
subclassing built in form builder, but also to get a grasp of what is  
allowe and what is not allowed in Rails parlance.

-Satynos

---

<div class="post-metadata">

**Author:** ![satynos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9bcb4/32.png) [@satynos](https://www.ruby-forum.com/u/satynos)\
**Post date:** [May 30, 2009, 11:56pm UTC](https://www.ruby-forum.com/t/problem-with-custom-form-builder/169176/3 "2009-05-30T23:56:06Z")

</div>

You’re making a module inherit from a class and this is wrong.

Here’s an example of building a custom form builder →   
[http://onrails.org/articles/2008/06/13/advanced-rails-studio-custom-form-builder](http://onrails.org/articles/2008/06/13/advanced-rails-studio-custom-form-builder)

- 

Maurício Linhares  
[http://alinhavado.wordpress.com/](http://alinhavado.wordpress.com/) (pt-br) | [http://blog.codevader.com/](http://blog.codevader.com/)  
(en)

On Sat, May 30, 2009 at 4:42 PM, Saty N.

---

<div class="post-metadata">

**Author:** ![satynos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9bcb4/32.png) [@satynos](https://www.ruby-forum.com/u/satynos)\
**Post date:** [May 31, 2009, 2:59am UTC](https://www.ruby-forum.com/t/problem-with-custom-form-builder/169176/4 "2009-05-31T02:59:00Z")

</div>

Mauricio:

Thanks for the reponse. I didn’t quite get what you mean by I am making  
a module inherit from a class.

MyAPP - is top level module  
MyApp::FormBuilder - is class within my module MyApp and inherits from  
builtin rails FormBuilder class  
MyApp::FormHelper - is module within my module MyApp.

I don’t see where my class is being inherited from module.

thanks in advance.  
-Satynos

MaurÃ­cio Linhares wrote:

> You’re making a module inherit from a class and this is wrong.
> 
> Here’s an example of building a custom form builder →   
> [http://onrails.org/articles/2008/06/13/advanced-rails-studio-custom-form-builder](http://onrails.org/articles/2008/06/13/advanced-rails-studio-custom-form-builder)
> 
> - 
> 
> Maurï¿½cio Linhares  
> [http://alinhavado.wordpress.com/](http://alinhavado.wordpress.com/) (pt-br) | [http://blog.codevader.com/](http://blog.codevader.com/)  
> (en)
> 
> On Sat, May 30, 2009 at 4:42 PM, Saty N.

---

<div class="post-metadata">

**Author:** ![satynos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9bcb4/32.png) [@satynos](https://www.ruby-forum.com/u/satynos)\
**Post date:** [May 31, 2009, 3:41am UTC](https://www.ruby-forum.com/t/problem-with-custom-form-builder/169176/5 "2009-05-31T03:41:44Z")

</div>

On May 31, 1:59 am, Saty N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I don’t see where my class is being inherited from module.

You’ve written

module FormHelper \< ActionView::Helpers::FormHelper  
end

which doesn’t make any sense - modules can’t inherit from anything.

Fre

---

<div class="post-metadata">

**Author:** ![satynos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9bcb4/32.png) [@satynos](https://www.ruby-forum.com/u/satynos)\
**Post date:** [May 31, 2009, 5:36am UTC](https://www.ruby-forum.com/t/problem-with-custom-form-builder/169176/6 "2009-05-31T05:36:56Z")

</div>

Fre:

That was a typo. In my actual implementation FormHelper is a module and  
it doesn’t inherit the builtin FormHelper, but includes it. So there was  
no problem. The problem I was having is with the FormBuilder itself. I  
beleive there was other code files that were creating the problem. Once  
I create a new rails app from scratch, everything works fine.

Thanks for all the feedback.  
-Satynos

Frederick C. wrote:

> On May 31, 1:59ï¿½am, Saty N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > I don’t see where my class is being inherited from module.
> 
> You’ve written
> 
> module FormHelper \< ActionView::Helpers::FormHelper  
> end
> 
> which doesn’t make any sense - modules can’t inherit from anything.
> 
> Fre
