aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--actionpack/lib/action_view/helpers/form_helper.rb33
-rwxr-xr-xactionpack/test/template/date_helper_test.rb4
-rw-r--r--actionpack/test/template/form_helper_test.rb10
-rw-r--r--actionpack/test/template/form_options_helper_test.rb6
5 files changed, 22 insertions, 33 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index d485d87971..62fae65370 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Change form_for and fields_for method signatures to take object name and object as separate arguments rather than as a Hash. [DHH]
+
* Introduce :selected option to the select helper. Allows you to specify a selection other than the current value of object.method. Specify :selected => nil to leave all options unselected. #2991 [Jonathan Viney <jonathan@bluewire.net.nz>]
* Initialize @optional in routing code to avoid warnings about uninitialized access to an instance variable. [Nicholas Seckar]
diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb
index 418b000163..4e24bfc702 100644
--- a/actionpack/lib/action_view/helpers/form_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_helper.rb
@@ -83,12 +83,12 @@ module ActionView
# That in itself is a modest increase in comfort. The big news is that form_for allows us to more easily escape the instance
# variable convention, so while the stand-alone approach would require <tt>text_field :person, :name, :object => person</tt>
# to work with local variables instead of instance ones, the form_for calls remain the same. You simply declare once with
- # <tt>:person => person</tt> and all subsequent field calls save <tt>:person</tt> and <tt>:object => person</tt>.
+ # <tt>:person, person</tt> and all subsequent field calls save <tt>:person</tt> and <tt>:object => person</tt>.
#
# Also note that form_for doesn't create an exclusive scope. It's still possible to use both the stand-alone FormHelper methods
# and methods from FormTagHelper. Example:
#
- # <% form_for :person => @person, :url => { :action => "update" } do |f| %>
+ # <% form_for :person, @person, :url => { :action => "update" } do |f| %>
# First name: <%= f.text_field :first_name %>
# Last name : <%= f.text_field :last_name %>
# Biography : <%= text_area :person, :biography %>
@@ -97,43 +97,30 @@ 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 form_for(options, *parameters_for_url, &proc)
- keys = [ :url, :method, :multipart ]
- leftover_keys = (options.keys - keys)
-
- case leftover_keys.length
- when 0 then raise 'No object given!'
- when 1 then
- object_name = leftover_keys.first
- object = options[object_name]
- else
- raise "Too many options: #{options.inspect}"
- end
-
- url_for_options = options[:url]
+ def form_for(object_name, object, options = {}, &proc)
+ url_for_options = options[:url]
additional_options = options.reject { |k, v| ![ :method, :multipart ].include?(k) }
-
- concat(form_tag(url_for_options, additional_options, *parameters_for_url), proc.binding)
- fields_for({ object_name => object }, &proc)
+ concat(form_tag(url_for_options, additional_options), proc.binding)
+ fields_for(object_name, object, &proc)
concat(end_form_tag, proc.binding)
end
# Creates a scope around a specific model object like form_for, but doesn't create the form tags themselves. This makes
# fields_for suitable for specifying additional model objects in the same form. Example:
#
- # <% form_for :person => @person, :url => { :action => "update" } do |person_form| %>
+ # <% form_for :person, @person, :url => { :action => "update" } do |person_form| %>
# First name: <%= person_form.text_field :first_name %>
# Last name : <%= person_form.text_field :last_name %>
#
- # <% fields_for :permission => @person.permission do |permission_fields| %>
+ # <% fields_for :permission, @person.permission do |permission_fields| %>
# Admin? : <%= permission_fields.check_box :admin %>
# <% end %>
# <% end %>
#
# 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 = {}, &proc)
- form_builder = FormBuilder.new(object.keys.first, object.values.first, self, proc)
+ def fields_for(object_name, object, &proc)
+ form_builder = FormBuilder.new(object_name, object, self, proc)
proc.call(form_builder)
end
diff --git a/actionpack/test/template/date_helper_test.rb b/actionpack/test/template/date_helper_test.rb
index bb6cd19013..7197a1a9c1 100755
--- a/actionpack/test/template/date_helper_test.rb
+++ b/actionpack/test/template/date_helper_test.rb
@@ -507,7 +507,7 @@ class DateHelperTest < Test::Unit::TestCase
_erbout = ''
- fields_for :post => @post do |f|
+ fields_for :post, @post do |f|
_erbout.concat f.date_select(:written_on)
end
@@ -524,7 +524,7 @@ class DateHelperTest < Test::Unit::TestCase
_erbout = ''
- fields_for :post => @post do |f|
+ fields_for :post, @post do |f|
_erbout.concat f.datetime_select(:updated_at)
end
diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb
index ae8cc50a73..a38e3c6728 100644
--- a/actionpack/test/template/form_helper_test.rb
+++ b/actionpack/test/template/form_helper_test.rb
@@ -199,7 +199,7 @@ class FormHelperTest < Test::Unit::TestCase
def test_form_for
_erbout = ''
- form_for(:post => @post) do |f|
+ form_for(:post, @post) do |f|
_erbout.concat f.text_field(:title)
_erbout.concat f.text_area(:body)
_erbout.concat f.check_box(:secret)
@@ -219,7 +219,7 @@ class FormHelperTest < Test::Unit::TestCase
def test_fields_for
_erbout = ''
- fields_for(:post => @post) do |f|
+ fields_for(:post, @post) do |f|
_erbout.concat f.text_field(:title)
_erbout.concat f.text_area(:body)
_erbout.concat f.check_box(:secret)
@@ -237,11 +237,11 @@ class FormHelperTest < Test::Unit::TestCase
def test_form_for_and_fields_for
_erbout = ''
- form_for(:post => @post) do |post_form|
+ form_for(:post, @post) do |post_form|
_erbout.concat post_form.text_field(:title)
_erbout.concat post_form.text_area(:body)
- fields_for(:parent_post => @post) do |parent_fields|
+ fields_for(:parent_post, @post) do |parent_fields|
_erbout.concat parent_fields.check_box(:secret)
end
end
@@ -256,4 +256,4 @@ class FormHelperTest < Test::Unit::TestCase
assert_dom_equal expected, _erbout
end
-end \ No newline at end of file
+end
diff --git a/actionpack/test/template/form_options_helper_test.rb b/actionpack/test/template/form_options_helper_test.rb
index 76c556606c..f468b69c7e 100644
--- a/actionpack/test/template/form_options_helper_test.rb
+++ b/actionpack/test/template/form_options_helper_test.rb
@@ -229,7 +229,7 @@ class FormOptionsHelperTest < Test::Unit::TestCase
_erbout = ''
- fields_for :post => @post do |f|
+ fields_for :post, @post do |f|
_erbout.concat f.select(:category, %w( abe <mus> hest))
end
@@ -330,7 +330,7 @@ class FormOptionsHelperTest < Test::Unit::TestCase
_erbout = ''
- fields_for :post => @post do |f|
+ fields_for :post, @post do |f|
_erbout.concat f.collection_select(:author_name, @posts, :author_name, :author_name)
end
@@ -386,7 +386,7 @@ class FormOptionsHelperTest < Test::Unit::TestCase
_erbout = ''
- fields_for :firm => @firm do |f|
+ fields_for :firm, @firm do |f|
_erbout.concat f.time_zone_select(:time_zone)
end