diff --git a/lib/sweet-alert2-rails/view_helpers.rb b/lib/sweet-alert2-rails/view_helpers.rb index 1cbda66..27f2a25 100644 --- a/lib/sweet-alert2-rails/view_helpers.rb +++ b/lib/sweet-alert2-rails/view_helpers.rb @@ -3,6 +3,17 @@ module ViewHelpers def link_to(*args, &block) html_options = args[block_given? ? 1 : 2] || {} + if options_has_confirm?(html_options) + html_options['data-sweet-alert-confirm'] = html_options.delete(:confirm) || + html_options[:data].delete(:confirm) + end + + super *args, &block + end + + def button_to(*args, &block) + html_options = args[block_given? ? 1 : 2] || {} + if options_has_confirm?(html_options) html_options['data-sweet-alert-confirm'] = html_options.delete(:confirm) || html_options[:data].delete(:confirm) @@ -19,15 +30,19 @@ def submit_tag(value = 'Save changes', options = {}) super value, options end - def button_tag(*args, &block) - html_options = args[block_given? ? 0 : 1] || {} + def button_tag(content_or_options = nil, options = nil, &block) + if content_or_options.is_a? Hash + html_options = content_or_options + else + html_options = options || {} + end if options_has_confirm?(html_options) html_options['data-sweet-alert-confirm'] = html_options.delete(:confirm) || html_options[:data].delete(:confirm) end - super *args, &block + super content_or_options, options, &block end protected