diff options
author | Piotr Sarnacki <drogus@gmail.com> | 2012-04-28 23:02:39 -0700 |
---|---|---|
committer | Piotr Sarnacki <drogus@gmail.com> | 2012-04-28 23:02:39 -0700 |
commit | beba8267c96a3dbc1f505ecc099dbf14db8dde4c (patch) | |
tree | 22d28096089a333e16b14111f6cd484f5ab4dcfd /actionpack | |
parent | 7dc83f78232a6dfcdd70292e831403933f57347b (diff) | |
download | rails-beba8267c96a3dbc1f505ecc099dbf14db8dde4c.tar.gz rails-beba8267c96a3dbc1f505ecc099dbf14db8dde4c.tar.bz2 rails-beba8267c96a3dbc1f505ecc099dbf14db8dde4c.zip |
Lazy load `default_form_builder` if it's passed as a string
closes #3341
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/CHANGELOG.md | 2 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/form_helper.rb | 8 | ||||
-rw-r--r-- | actionpack/test/template/form_helper_test.rb | 17 |
3 files changed, 26 insertions, 1 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 566b6af378..e1b68d9f26 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,5 +1,7 @@ ## Rails 3.2.3 (unreleased) ## +* Allow to lazy load `default_form_builder` by passing a `String` instead of a constant. *Piotr Sarnacki* + * Fix #5632, render :inline set the proper rendered format. *Santiago Pastorino* * Fix textarea rendering when using plugins like HAML. Such plugins encode the first newline character in the content. This issue was introduced in https://github.com/rails/rails/pull/5191 *James Coleman* diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 252fe1ed03..a3409ee3c7 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -9,6 +9,7 @@ require 'active_support/core_ext/module/method_names' require 'active_support/core_ext/object/blank' require 'active_support/core_ext/string/output_safety' require 'active_support/core_ext/array/extract_options' +require 'active_support/core_ext/string/inflections' module ActionView # = Action View Form Helpers @@ -959,9 +960,14 @@ module ActionView object_name = ActiveModel::Naming.param_key(object) end - builder = options[:builder] || ActionView::Base.default_form_builder + builder = options[:builder] || default_form_builder builder.new(object_name, object, self, options, block) end + + def default_form_builder + builder = ActionView::Base.default_form_builder + builder.respond_to?(:constantize) ? builder.constantize : builder + end end class InstanceTag diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index 7eeede7087..3f459bad2e 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -2033,6 +2033,23 @@ class FormHelperTest < ActionView::TestCase ActionView::Base.default_form_builder = old_default_form_builder end + def test_lazy_loading_default_form_builder + old_default_form_builder, ActionView::Base.default_form_builder = + ActionView::Base.default_form_builder, "FormHelperTest::LabelledFormBuilder" + + form_for(@post) do |f| + concat f.text_field(:title) + end + + expected = whole_form('/posts/123', 'edit_post_123', 'edit_post', :method => 'patch') do + "<label for='title'>Title:</label> <input name='post[title]' type='text' id='post_title' value='Hello World' /><br/>" + end + + assert_dom_equal expected, output_buffer + ensure + ActionView::Base.default_form_builder = old_default_form_builder + end + def test_fields_for_with_labelled_builder output_buffer = fields_for(:post, @post, :builder => LabelledFormBuilder) do |f| concat f.text_field(:title) |