views:

362

answers:

1

Hello

I am trying to DRY up some code by moving some logic into the FormBuilder. After reading the documentation about how to select and alternative form builder the logical solution for me seemed to be something like this.

In the view

<% form_for @event, :builder => TestFormBuilder do |f| %>
    <%= f.test  %>
    <%= f.submit 'Update' %>
<% end %>

and then in app/helpers/application_helper.rb

module ApplicationHelper
    class TestFormBuilder < ActionView::Helpers::FormBuilder
        def test
            puts 'apa'
        end
    end
end

This, however, gives me an error at the "form_for"

  uninitialized constant ActionView::Base::CompiledTemplates::TestFormBuilder

Where am I doing it wrong?

+1  A: 

try with :

form_for @event, :builder => ApplicationHelper::TestFormBuilder do |f|
shingara
Thank you. That worked. Is this documented somewhere or have I missed something in the structure of rails?
nibbo
You need define a class. So you don't need put it in your ApplicationHelper. So you can put your class in your lib and use without namespace.
shingara