Skip to content
Browse files

Fix remote_form_for creates a non-ajax form. Closes #3741.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3545 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 796295d commit 7139e2a0e1c24788758ccd6131ba86243de84bf6 @seckar seckar committed Feb 6, 2006
View
2 actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Fix remote_form_for creates a non-ajax form. [Rick Olson]
+
* Don't let arbitrary classes match as controllers -- a potentially dangerous bug. [Nicholas Seckar]
* Fix Routing tests. Fix routing where failing to match a controller would prevent the rest of routes from being attempted. [Nicholas Seckar]
View
10 actionpack/lib/action_view/helpers/form_helper.rb
@@ -117,13 +117,17 @@ module FormHelper
def form_for(object_name, object, options = {}, &proc)
raise ArgumentError, "form_for requires a block!" unless proc
- url_options = options.delete :url
+ url_options = options.delete(:url) || {}
form_tag_selector = options.delete(:form_tag_selector) || :form_tag
- form_options = {}
+ form_options = {}
[: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|
- concat send(form_tag_selector, url_options, form_options), proc.binding
+ if form_tag_selector == :form_remote_tag
+ concat send(form_tag_selector, form_options.merge(:url => url_options)), proc.binding
+ else
+ concat send(form_tag_selector, url_options, form_options), proc.binding
+ end
builder.build_form(url_options, form_options) { proc.call builder }
concat end_form_tag, proc.binding
end
View
2 actionpack/lib/action_view/helpers/prototype_helper.rb
@@ -172,7 +172,7 @@ def form_remote_tag(options = {})
# Works like form_remote_tag, but uses form_for semantics.
def remote_form_for(object_name, object, options = {}, &proc)
- form_for(object_name, object, options.merge(:form_for_select => :form_remote_tag), &proc)
+ form_for(object_name, object, options.merge(:form_tag_selector => :form_remote_tag), &proc)
end
alias_method :form_remote_for, :remote_form_for
View
2 actionpack/test/template/form_helper_test.rb
@@ -304,7 +304,7 @@ def test_remote_form_for_with_labelled_builder
end
expected =
- "<form action='http://www.example.com' method='post'>" +
+ %(<form action="http://www.example.com" onsubmit="new Ajax.Request('http://www.example.com', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;" method="post">) +
"<label for='title'>Title:</label> <input name='post[title]' size='30' type='text' id='post_title' value='Hello World' /><br/>" +
"<label for='body'>Body:</label> <textarea name='post[body]' id='post_body' rows='20' cols='40'>Back to the hill and over it again!</textarea><br/>" +
"<label for='secret'>Secret:</label> <input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />" +

0 comments on commit 7139e2a

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