Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
Set default form builder for a controller #19736
Form builders can only be overridden per call of
This is modeled after how a layout is defined per controller.
This override has a higher prescidence than the
Given a section specific form builder:
class AdminFormBuilder < ActionView::Helpers::FormBuilder def admin_element(name) # snip end end
And an abstract controller superclass for an admin area:
class AdminAreaController < ApplicationController form_builder AdminAreaFormBuilder end
Any calls to
Tested in this example app:
The existing but insufficient workarounds I have been able to identify are:
@senny it’s not that writing a wrapper like
The background to this patch is that we’re starting to use more custom form builders in Shopify (a rather large Rails project) and are hitting a complexity wall with the workarounds mentioned above.
Overriding a custom
Rails allows you to scope nearly everything cleanly to split an app into sections, with this notable exception. Especially since you have the ability to override the form builder globally.
Shopify isn't the first project where I have wanted this feature either, FWIW.
About the feature, I can see as it can be useful. This would be similar to when we define which helper module is loaded by controller (if we disable the global require).
About the implementation, this is coupling Action View with Action Controller. How about instead making Action View asking Action Controller what is the form builder, we do not set it when creating the
Given we will have a default form builder per action view instance and it
Another thing, maybe we should call the singleton method
On Mon, Apr 13, 2015, 12:51 Kevin McPhillips firstname.lastname@example.org
@rafaelfranca Great feedback.
I think it's a great idea to deprecate the global
I'll rename the method to be
About the implementation.
I can delegate
That makes the implementation in the
def default_form_builder_class builder = default_form_builder || ActionView::Base.default_form_builder
And that works.
But when the view is not an instance of
I'm not sure if that means this test is broken, or if this is a valid case.
I can do
What do you think?
I think instead of delegating we should do the same we do with
And we define:
def default_form_builder_class builder = @_default_form_builder || ActionView::Base.default_form_builder
Or use a
I think this would fix the problem with the custom view context.
On Tue, Apr 14, 2015 at 1:56 PM, Rafael Mendonça França <