Permalink
Browse files

form_for should pass :remote to form_tag through html_options

  • Loading branch information...
1 parent 59e9478 commit a3349f845ffa2415e12ac9e26b4f7300d7edd3ef @stevestmartin stevestmartin committed with josh Jan 31, 2010
Showing with 21 additions and 0 deletions.
  1. +2 −0 actionpack/lib/action_view/helpers/form_helper.rb
  2. +19 −0 actionpack/test/template/form_helper_test.rb
@@ -280,6 +280,8 @@ def form_for(record_or_name_or_array, *args, &proc)
args.unshift object
end
+ options[:html][:remote] = true if options.delete(:remote)
+
concat(form_tag(options.delete(:url) || {}, options.delete(:html) || {}))
fields_for(object_name, *(args << options), &proc)
concat('</form>'.html_safe!)
@@ -451,6 +451,25 @@ def test_form_for_with_method
assert_dom_equal expected, output_buffer
end
+ def test_form_for_with_remote
+ form_for(:post, @post, :remote => true, :html => { :id => 'create-post', :method => :put }) do |f|
+ concat f.text_field(:title)
+ concat f.text_area(:body)
+ concat f.check_box(:secret)
+ end
+
+ expected =
+ "<form action='http://www.example.com' id='create-post' method='post' data-remote='true'>" +
+ "<div style='margin:0;padding:0;display:inline'><input name='_method' type='hidden' value='put' /></div>" +
+ "<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]' type='hidden' value='0' />" +
+ "<input name='post[secret]' checked='checked' type='checkbox' id='post_secret' value='1' />" +
+ "</form>"
+
+ assert_dom_equal expected, output_buffer
+ end
+
def test_form_for_without_object
form_for(:post, :html => { :id => 'create-post' }) do |f|
concat f.text_field(:title)

1 comment on commit a3349f8

Contributor

nicolasblanco commented on a3349f8 Feb 1, 2010

I really like this, being able to just add :remote => true to a form_for to enable a remote form!

Thanks for this.

Please sign in to comment.