From 666537572d689c81eef7590f7ff3a146f3a82b29 Mon Sep 17 00:00:00 2001 From: Rick Olson Date: Sun, 26 Mar 2006 20:21:27 +0000 Subject: finish form_for change, allow hash as the second param: form_for :post, :url => { }. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4051 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/CHANGELOG | 4 ++-- actionpack/lib/action_view/helpers/form_helper.rb | 9 ++++++--- actionpack/test/template/form_helper_test.rb | 12 ++++++------ 3 files changed, 14 insertions(+), 11 deletions(-) (limited to 'actionpack') diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 0d69ccc6af..96af65a578 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -2,11 +2,11 @@ * Change #form_for and #fields_for so that the second argument is not required [Dave Thomas] - <% form_for :post, @post do |f| -%> + <% form_for :post, @post, :url => { :action => 'create' } do |f| -%> becomes... - <% form_for :post do |f| -%> + <% form_for :post, :url => { :action => 'create' } do |f| -%> * Update to script.aculo.us 1.6 [Thomas Fuchs] diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 8380993af8..7c8748d604 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -120,10 +120,11 @@ module ActionView # form_for(name, object, options.merge(:builder => LabellingFormBuiler), &proc) # end # - def form_for(object_name, object = nil, options = {}, &proc) + def form_for(object_name, *args, &proc) raise ArgumentError, "Missing block" unless block_given? + options = args.last.is_a?(Hash) ? args.pop : {} concat(form_tag(options.delete(:url) || {}, options.delete(:html) || {}), proc.binding) - fields_for(object_name, object, options, &proc) + fields_for(object_name, *(args << options), &proc) concat('', proc.binding) end @@ -141,8 +142,10 @@ 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 = nil, options = {}, &proc) + def fields_for(object_name, *args, &proc) 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)) end diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb index acff699535..a40a1ff662 100644 --- a/actionpack/test/template/form_helper_test.rb +++ b/actionpack/test/template/form_helper_test.rb @@ -215,14 +215,14 @@ class FormHelperTest < Test::Unit::TestCase def test_form_for _erbout = '' - form_for(:post, @post) do |f| + form_for(:post, @post, :html => { :id => 'create-post' }) do |f| _erbout.concat f.text_field(:title) _erbout.concat f.text_area(:body) _erbout.concat f.check_box(:secret) end expected = - "
" + + "" + "" + "" + "" + @@ -235,14 +235,14 @@ class FormHelperTest < Test::Unit::TestCase def test_form_for_without_object _erbout = '' - form_for(:post) do |f| + form_for(:post, :html => { :id => 'create-post' }) do |f| _erbout.concat f.text_field(:title) _erbout.concat f.text_area(:body) _erbout.concat f.check_box(:secret) end expected = - "" + + "" + "" + "" + "" + @@ -294,7 +294,7 @@ class FormHelperTest < Test::Unit::TestCase def test_form_for_and_fields_for _erbout = '' - form_for(:post, @post) do |post_form| + form_for(:post, @post, :html => { :id => 'create-post' }) do |post_form| _erbout.concat post_form.text_field(:title) _erbout.concat post_form.text_area(:body) @@ -304,7 +304,7 @@ class FormHelperTest < Test::Unit::TestCase end expected = - "" + + "" + "" + "" + "" + -- cgit v1.2.3