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
This commit is contained in:
Sam Stephenson 2006-02-08 20:46:15 +00:00
parent 73ed47ddec
commit 803b9a41af
3 changed files with 23 additions and 2 deletions

@ -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]

@ -119,12 +119,12 @@ def form_for(object_name, object, options = {}, &proc)
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

@ -338,4 +338,23 @@ def test_fields_for_with_labelled_builder
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