aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRick Olson <technoweenie@gmail.com>2006-03-26 20:21:27 +0000
committerRick Olson <technoweenie@gmail.com>2006-03-26 20:21:27 +0000
commit666537572d689c81eef7590f7ff3a146f3a82b29 (patch)
tree47fffa68159c5e74001ee49ff94429881c8a3233
parent26837824555bfa749287f691e8ca96137dcfef7d (diff)
downloadrails-666537572d689c81eef7590f7ff3a146f3a82b29.tar.gz
rails-666537572d689c81eef7590f7ff3a146f3a82b29.tar.bz2
rails-666537572d689c81eef7590f7ff3a146f3a82b29.zip
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
-rw-r--r--actionpack/CHANGELOG4
-rw-r--r--actionpack/lib/action_view/helpers/form_helper.rb9
-rw-r--r--actionpack/test/template/form_helper_test.rb12
3 files changed, 14 insertions, 11 deletions
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('</form>', 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 =
- "<form action='http://www.example.com' method='post'>" +
+ "<form action='http://www.example.com' id='create-post' 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' />" +
@@ -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 =
- "<form action='http://www.example.com' method='post'>" +
+ "<form action='http://www.example.com' id='create-post' 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' />" +
@@ -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 =
- "<form action='http://www.example.com' method='post'>" +
+ "<form action='http://www.example.com' id='create-post' 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='parent_post[secret]' checked='checked' type='checkbox' id='parent_post_secret' value='1' />" +