I have a sub-classified default form builder to add some additional methods. Sample code below.
module ApplicationHelper class AppFormBuilder < ActionView::Helpers::FormBuilder def coordinates_field(method, options = {}) options[:readonly] = 'true' .... @template.text_field(@object_name, method, objectify_options(options)) end end end
This works well, but to use it I need to change the view code for each form using the coordinates_field method, i.e.
<%= form_for @object, :builder => ApplicationHelper::AppFormBuilder do |f| %> ... <% end %>
It seems theoretically possible to change the default form builder around the world ( config.action_view.default_form_builder ), but I can't get it to work. This is what I tried in /config/application.rb :
module Web class Application < Rails::Application ... config.action_view.default_form_builder = "ApplicationHelper::AppFormBuilder" end end
Which results in an undefined error for the "new" method for "ApplicationHelper :: AppFormBuilder": String when I hit a view that has a form.
If I try instead
config.action_view.default_form_builder = ApplicationHelper::AppFormBuilder
I get the error * config.action_view.default_form_builder = ApplicationHelper :: AppFormBuilder * when the application starts.
Can anyone give directions on how to make this work?
source share