Skip to content
Browse files

link_to_remote and button_to_remote now support :confirm

  • Loading branch information...
1 parent 9ad8d34 commit c3baf8b767bdfb27b90b2120f9512d9697e5e932 @erikstmartin erikstmartin committed with stefanpenner
Showing with 22 additions and 0 deletions.
  1. +12 −0 actionpack/lib/action_view/helpers/ajax_helper.rb
  2. +10 −0 actionpack/test/template/ajax_helper_test.rb
View
12 actionpack/lib/action_view/helpers/ajax_helper.rb
@@ -293,6 +293,7 @@ def link_to_remote(name, options, html_options = {})
attributes = {}
attributes.merge!(:rel => "nofollow") if options[:method] && options[:method].downcase == "delete"
attributes.merge!(extract_remote_attributes!(options))
+ attributes.merge!(extract_confirm_attributes!(options))
attributes.merge!(html_options)
content_tag(:a, name, attributes.merge(:href => "#"))
@@ -304,6 +305,7 @@ def link_to_remote(name, options, html_options = {})
# and defining callbacks is the same as link_to_remote.
def button_to_remote(name, options = {}, html_options = {})
attributes = html_options.merge!(:type => "button", :value => name)
+ attributes.merge!(extract_confirm_attributes!(options))
attributes.merge!(extract_remote_attributes!(options))
tag(:input, attributes)
@@ -483,6 +485,16 @@ def script_decorator(options)
private
+ def extract_confirm_attributes!(options)
+ attributes = {}
+
+ if options && options[:confirm]
+ attributes["data-confirm"] = options.delete(:confirm)
+ end
+
+ attributes
+ end
+
def extract_remote_attributes!(options)
attributes = options.delete(:html) || {}
View
10 actionpack/test/template/ajax_helper_test.rb
@@ -101,6 +101,11 @@ def setup
link_to_remote("Remote", { :url => { :action => "whatnot's" } })
end
+ test "link_to_remote with confirm" do
+ assert_dom_equal %(<a class=\"fine\" href=\"#\" data-remote=\"true\" data-url=\"http://www.example.com/whatnot\" data-method=\"delete\" rel=\"nofollow\" data-confirm="Are you sure?">Remote confirm</a>),
+ link_to_remote("Remote confirm", { :url => { :action => "whatnot" }, :method => "delete", :confirm => "Are you sure?"}, { :class => "fine" })
+ end
+
test "button_to_remote" do
assert_dom_equal %(<input class=\"fine\" type=\"button\" value=\"Remote outpost\" data-remote=\"true\" data-url=\"http://www.example.com/whatnot\" />),
button_to_remote("Remote outpost", { :url => { :action => "whatnot" }}, { :class => "fine" })
@@ -114,6 +119,11 @@ def setup
button_to_remote("Remote outpost", :failure => "alert(request.reponseText)", :url => { :action => "whatnot", :a => '10', :b => '20' })
end
+ test "button_to_remote with confirm" do
+ assert_dom_equal %(<input class=\"fine\" type=\"button\" value=\"Remote outpost\" data-remote=\"true\" data-url=\"http://www.example.com/whatnot\" data-confirm="Are you sure?" />),
+ button_to_remote("Remote outpost", { :url => { :action => "whatnot" }, :confirm => "Are you sure?"}, { :class => "fine" })
+ end
+
test "periodically_call_remote" do
assert_dom_equal %(<script data-url=\"http://www.example.com/mehr_bier\" data-observe=\"true\" data-update-success=\"schremser_bier\" type=\"application/json\" data-periodical=\"true\"></script>),
periodically_call_remote(:update => "schremser_bier", :url => { :action => "mehr_bier" })

0 comments on commit c3baf8b

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