refactoring AjaxHelper a bit so that it calls shared method from JavascriptHelper to add attributes for :confirm

This commit is contained in:
Erik St. Martin
2010-01-24 12:37:26 -05:00
committed by Stefan Penner
parent 463fc71107
commit fbb56f7ee8

View File

@@ -293,7 +293,11 @@ module ActionView
attributes = {}
attributes.merge!(:rel => "nofollow") if options[:method] && options[:method].downcase == "delete"
attributes.merge!(extract_remote_attributes!(options))
attributes.merge!(extract_confirm_attributes!(options))
if confirm = options.delete(:confirm)
add_confirm_to_attributes!(attributes, confirm)
end
attributes.merge!(html_options)
content_tag(:a, name, attributes.merge(:href => "#"))
@@ -305,7 +309,11 @@ module ActionView
# 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))
if confirm = options.delete(:confirm)
add_confirm_to_attributes!(attributes, confirm)
end
attributes.merge!(extract_remote_attributes!(options))
tag(:input, attributes)
@@ -485,16 +493,6 @@ module ActionView
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) || {}