Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge [5422] from trunk.

git-svn-id: http://svn-commit.rubyonrails.org/rails/branches/1-2-pre-release@5423 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 5350fda95de6b49026e5cc76ed4689762e713f8c 1 parent 5fac326
@jeremy jeremy authored
View
2  actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Set ActionView::Base.default_form_builder once rather than passing the :builder option to every form or overriding the form helper methods. [Jeremy Kemper]
+
* Deprecate expire_matched_fragments. Use expire_fragment instead. #6535 [Bob Silva]
* Update to latest Prototype, which doesn't serialize disabled form elements, adds clone() to arrays, empty/non-string Element.update() and adds a fixes excessive error reporting in WebKit beta versions [Thomas Fuchs]
View
11 actionpack/lib/action_view/helpers/form_helper.rb
@@ -142,11 +142,13 @@ def form_for(object_name, *args, &proc)
#
# Note: This also works for the methods in FormOptionHelper and DateHelper that are designed to work with an object as base.
# Like collection_select and datetime_select.
- def fields_for(object_name, *args, &proc)
+ def fields_for(object_name, *args, &block)
raise ArgumentError, "Missing block" unless block_given?
options = args.last.is_a?(Hash) ? args.pop : {}
object = args.first
- yield((options[:builder] || FormBuilder).new(object_name, object, self, options, proc))
+
+ builder = options[:builder] || ActionView::Base.default_form_builder
+ yield builder.new(object_name, object, self, options, block)
end
# Returns an input tag of the "text" type tailored for accessing a specified attribute (identified by +method+) on an object
@@ -436,4 +438,9 @@ def radio_button(method, tag_value, options = {})
end
end
end
+
+ class Base
+ cattr_accessor :default_form_builder
+ self.default_form_builder = ::ActionView::Helpers::FormBuilder
+ end
end
View
26 actionpack/test/template/form_helper_test.rb
@@ -396,7 +396,31 @@ def test_form_for_with_labelled_builder
assert_dom_equal expected, _erbout
end
-
+
+ def test_default_form_builder
+ old_default_form_builder, ActionView::Base.default_form_builder =
+ ActionView::Base.default_form_builder, LabelledFormBuilder
+
+ _erbout = ''
+ form_for(:post, @post) do |f|
+ _erbout.concat f.text_field(:title)
+ _erbout.concat f.text_area(:body)
+ _erbout.concat f.check_box(:secret)
+ end
+
+ expected =
+ "<form action='http://www.example.com' method='post'>" +
+ "<label for='title'>Title:</label> <input name='post[title]' size='30' type='text' id='post_title' value='Hello World' /><br/>" +
+ "<label for='body'>Body:</label> <textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea><br/>" +
+ "<label for='secret'>Secret:</label> <input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />" +
+ "<input name='post[secret]' type='hidden' value='0' /><br/>" +
+ "</form>"
+
+ assert_dom_equal expected, _erbout
+ ensure
+ ActionView::Base.default_form_builder = old_default_form_builder
+ end
+
# Perhaps this test should be moved to prototype helper tests.
def test_remote_form_for_with_labelled_builder
self.extend ActionView::Helpers::PrototypeHelper
Please sign in to comment.
Something went wrong with that request. Please try again.