aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Stephenson <sam@37signals.com>2006-02-08 20:46:15 +0000
committerSam Stephenson <sam@37signals.com>2006-02-08 20:46:15 +0000
commit803b9a41af46210da842afdba032c34109514942 (patch)
tree0ed7d2d1c893fb6c74df9198f8fb3d28e4e3bbd5
parent73ed47ddec458a512178de584e896ebb276c0125 (diff)
downloadrails-803b9a41af46210da842afdba032c34109514942.tar.gz
rails-803b9a41af46210da842afdba032c34109514942.tar.bz2
rails-803b9a41af46210da842afdba032c34109514942.zip
Add :html option for specifying form tag options in form_for
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3552 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--actionpack/lib/action_view/helpers/form_helper.rb4
-rw-r--r--actionpack/test/template/form_helper_test.rb19
3 files changed, 23 insertions, 2 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index fc00517cea..7376f5ea0a 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Add :html option for specifying form tag options in form_for. [Sam Stephenson]
+
* Replace dubious controller parent class in filter docs. #3655, #3722 [info@rhalff.com, eigentone@gmail.com]
* Don't interpret the :value option on text_area as an html attribute. Set the text_area's value. #3752 [gabriel@gironda.org]
diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb
index 43770eec8d..872453b753 100644
--- a/actionpack/lib/action_view/helpers/form_helper.rb
+++ b/actionpack/lib/action_view/helpers/form_helper.rb
@@ -119,12 +119,12 @@ module ActionView
url_options = options.delete(:url) || {}
form_tag_selector = options.delete(:form_tag_selector) || :form_tag
- form_options = {}
+ form_options = options.delete(:html) || {}
[:method, :multipart].each { |key| form_options[key] = options.delete(key) if options.key? key }
fields_for(object_name, object, options.merge(:proc => proc)) do |builder|
if form_tag_selector == :form_remote_tag
- concat send(form_tag_selector, form_options.merge(:url => url_options)), proc.binding
+ concat send(form_tag_selector, form_options.merge(:url => url_options, :html => form_options)), proc.binding
else
concat send(form_tag_selector, url_options, form_options), proc.binding
end
diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb
index 83d50aae7a..1010598f65 100644
--- a/actionpack/test/template/form_helper_test.rb
+++ b/actionpack/test/template/form_helper_test.rb
@@ -338,4 +338,23 @@ class FormHelperTest < Test::Unit::TestCase
assert_dom_equal expected, _erbout
end
+
+ def test_form_for_with_html_options_adds_options_to_form_tag
+ _erbout = ''
+
+ form_for(:post, @post, :html => {:id => 'some_form', :class => 'some_class'}) do |f| end
+ expected = "<form action=\"http://www.example.com\" class=\"some_class\" id=\"some_form\" method=\"post\"></form>"
+
+ assert_dom_equal expected, _erbout
+ end
+
+ def test_remote_form_for_with_html_options_adds_options_to_form_tag
+ self.extend ActionView::Helpers::PrototypeHelper
+ _erbout = ''
+
+ remote_form_for(:post, @post, :html => {:id => 'some_form', :class => 'some_class'}) do |f| end
+ expected = "<form action=\"http://www.example.com\" class=\"some_class\" id=\"some_form\" method=\"post\" onsubmit=\"new Ajax.Request('http://www.example.com', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;\"></form>"
+
+ assert_dom_equal expected, _erbout
+ end
end