Skip to content
Browse files

finish form_for change, allow hash as the second param: form_for :pos…

…t, :url => { }.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4051 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 2683782 commit 666537572d689c81eef7590f7ff3a146f3a82b29 @technoweenie technoweenie committed Mar 26, 2006
View
4 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]
View
9 actionpack/lib/action_view/helpers/form_helper.rb
@@ -120,10 +120,11 @@ module FormHelper
# 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 @@ def form_for(object_name, object = nil, options = {}, &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, 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
View
12 actionpack/test/template/form_helper_test.rb
@@ -215,14 +215,14 @@ def test_auto_index
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 @@ def test_form_for
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 @@ def test_form_builder_does_not_have_form_for_method
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 @@ def test_form_for_and_fields_for
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' />" +

0 comments on commit 6665375

Please sign in to comment.
Something went wrong with that request. Please try again.