module ActionView::Helpers::UrlHelper

def button_to(name = nil, options = nil, html_options = nil, &block)

#
# "
#
#
#
# => "

method: "delete", remote: true, data: { confirm: 'Are you sure?', disable_with: 'loading...' }) %>
<%= button_to('Destroy', 'http://www.example.com',


#
"
#
#
#
# => "

method: :delete, data: { confirm: "Are you sure?" } %>
<%= button_to "Delete Image", { action: "delete", id: @image.id },


#
"
#
#
# => "

<%= button_to "Create", { action: "create" }, remote: true, form: { "data-type" => "json" } %>


#
"
#
# => "

<%= button_to "New", { action: "new" }, form_class: "new-thing" %>

#
"
#
# Make happy <%= @user.name %>
#
def button_to(name = nil, options = nil, html_options = nil, &block)
  html_options, options = options, name if block_given?
  options      ||= {}
  html_options ||= {}
  html_options = html_options.stringify_keys
  convert_boolean_attributes!(html_options, %w(disabled))
  url    = options.is_a?(String) ? options : url_for(options)
  remote = html_options.delete('remote')
  params = html_options.delete('params')
  method     = html_options.delete('method').to_s
  method_tag = BUTTON_TAG_METHOD_VERBS.include?(method) ? method_tag(method) : ''.html_safe
  form_method  = method == 'get' ? 'get' : 'post'
  form_options = html_options.delete('form') || {}
  form_options[:class] ||= html_options.delete('form_class') || 'button_to'
  form_options.merge!(method: form_method, action: url)
  form_options.merge!("data-remote" => "true") if remote
  request_token_tag = form_method == 'post' ? token_tag : ''
  html_options = convert_options_to_data_attributes(options, html_options)
  html_options['type'] = 'submit'
  button = if block_given?
    content_tag('button', html_options, &block)
  else
    html_options['value'] = name || url
    tag('input', html_options)
  end
  inner_tags = method_tag.safe_concat(button).safe_concat(request_token_tag)
  if params
    params.each do |param_name, value|
      inner_tags.safe_concat tag(:input, type: "hidden", name: param_name, value: value.to_param)
    end
  end
  content_tag('form', inner_tags, form_options)
end