mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
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
This commit is contained in:
parent
2683782455
commit
666537572d
3 changed files with 14 additions and 11 deletions
|
@ -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]
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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' />" +
|
||||
|
|
Loading…
Reference in a new issue