aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/CHANGELOG8
-rw-r--r--actionpack/lib/action_view/helpers/form_helper.rb4
-rw-r--r--actionpack/test/template/form_helper_test.rb39
3 files changed, 48 insertions, 3 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index 2e265f9745..0d69ccc6af 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,13 @@
*SVN*
+* Change #form_for and #fields_for so that the second argument is not required [Dave Thomas]
+
+ <% form_for :post, @post do |f| -%>
+
+ becomes...
+
+ <% form_for :post do |f| -%>
+
* Update to script.aculo.us 1.6 [Thomas Fuchs]
* Enable application/x-yaml processing by default [Jamis Buck]
diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb
index 72d4e6b475..8380993af8 100644
--- a/actionpack/lib/action_view/helpers/form_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_helper.rb
@@ -120,7 +120,7 @@ module ActionView
# form_for(name, object, options.merge(:builder => LabellingFormBuiler), &proc)
# end
#
- def form_for(object_name, object, options = {}, &proc)
+ def form_for(object_name, object = nil, options = {}, &proc)
raise ArgumentError, "Missing block" unless block_given?
concat(form_tag(options.delete(:url) || {}, options.delete(:html) || {}), proc.binding)
fields_for(object_name, object, options, &proc)
@@ -141,7 +141,7 @@ module ActionView
#
# 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, object, options = {}, &proc)
+ def fields_for(object_name, object = nil, options = {}, &proc)
raise ArgumentError, "Missing block" unless block_given?
yield((options[:builder] || FormBuilder).new(object_name, object, self, options, proc))
end
diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb
index cfeff6d7a7..acff699535 100644
--- a/actionpack/test/template/form_helper_test.rb
+++ b/actionpack/test/template/form_helper_test.rb
@@ -232,6 +232,26 @@ class FormHelperTest < Test::Unit::TestCase
assert_dom_equal expected, _erbout
end
+ def test_form_for_without_object
+ _erbout = ''
+
+ form_for(: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'>" +
+ "<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
+ "<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
+ "<input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />" +
+ "<input name='post[secret]' type='hidden' value='0' />" +
+ "</form>"
+
+ assert_dom_equal expected, _erbout
+ end
+
def test_fields_for
_erbout = ''
@@ -249,7 +269,24 @@ class FormHelperTest < Test::Unit::TestCase
assert_dom_equal expected, _erbout
end
-
+
+ def test_fields_for_without_object
+ _erbout = ''
+ fields_for(:post) do |f|
+ _erbout.concat f.text_field(:title)
+ _erbout.concat f.text_area(:body)
+ _erbout.concat f.check_box(:secret)
+ end
+
+ expected =
+ "<input name='post[title]' size='30' type='text' id='post_title' value='Hello World' />" +
+ "<textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea>" +
+ "<input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />" +
+ "<input name='post[secret]' type='hidden' value='0' />"
+
+ assert_dom_equal expected, _erbout
+ end
+
def test_form_builder_does_not_have_form_for_method
assert ! ActionView::Helpers::FormBuilder.instance_methods.include?('form_for')
end