aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorBob Remeika <bob.remeika@gmail.com>2009-11-04 23:18:15 -0800
committerStefan Penner <stefan.penner@gmail.com>2010-01-27 12:44:29 -0600
commit8c43c11a9dfd713cf613bb04c6074c82810d2f36 (patch)
tree7d856210cb7fcf4d14878b170aaaa37094840306 /actionpack
parent67b73ff27206fa63a65926faf3b5c69019595c47 (diff)
downloadrails-8c43c11a9dfd713cf613bb04c6074c82810d2f36.tar.gz
rails-8c43c11a9dfd713cf613bb04c6074c82810d2f36.tar.bz2
rails-8c43c11a9dfd713cf613bb04c6074c82810d2f36.zip
Added submit_to_remote helper
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_view/helpers/ajax_helper.rb10
-rw-r--r--actionpack/test/javascript/ajax_test.rb12
2 files changed, 21 insertions, 1 deletions
diff --git a/actionpack/lib/action_view/helpers/ajax_helper.rb b/actionpack/lib/action_view/helpers/ajax_helper.rb
index 9f1ca138eb..1a75f9372b 100644
--- a/actionpack/lib/action_view/helpers/ajax_helper.rb
+++ b/actionpack/lib/action_view/helpers/ajax_helper.rb
@@ -48,6 +48,16 @@ module ActionView
tag(:input, attributes)
end
+ def submit_to_remote(name, value, options = {})
+ html_options = options.delete(:html) || {}
+ html_options.merge!(:name => name, :value => value, :type => "submit")
+
+ attributes = extract_remote_attributes!(options)
+ attributes.merge!(html_options)
+
+ tag(:input, attributes)
+ end
+
def periodically_call_remote(options = {})
attributes = extract_observer_attributes!(options)
attributes["data-js-type"] = "periodical_executer"
diff --git a/actionpack/test/javascript/ajax_test.rb b/actionpack/test/javascript/ajax_test.rb
index f1207e938d..f4e766d77e 100644
--- a/actionpack/test/javascript/ajax_test.rb
+++ b/actionpack/test/javascript/ajax_test.rb
@@ -332,7 +332,7 @@ end
class ButtonToRemoteTest < AjaxTestCase
def button(options, html = {})
- button_to_remote("Remote outpost", options, html)
+ button_to_remote("RemoteOutpost", options, html)
end
def url_for(*)
@@ -355,6 +355,16 @@ class ButtonToRemoteTest < AjaxTestCase
end
end
+class SubmitToRemoteTest < AjaxTestCase
+ test "basic" do
+ expected = %(<input class="fine" type="submit" name="foo" value="bar" data-url="/url/hash" data-js-type="remote" data-update-success=".klass" />)
+ options = { :url => {:action => "whatnot"}, :update => ".klass", :html => { :class => "fine" } }
+
+ assert_dom_equal expected,
+ submit_to_remote("foo", "bar", options)
+ end
+end
+
class ScriptDecoratorTest < AjaxTestCase
def decorator()
script_decorator("data-js-type" => "foo_type", "data-foo" => "bar", "data-baz" => "bang")