module ActionView::Helpers::UrlHelper

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


# "
#
#
# => "

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

#
"
#
#
# => "

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

#
"
#
#
# Make happy <%= @user.name %>
#
# => "

<%= button_to "New", new_article_path, params: { time: Time.now } %>

#
"
#
#
# => "

<%= button_to "New", new_article_path %>

#
"
#
#
# => "

<%= button_to "New", action: "new" %>
==== Examples

* :params - \Hash of parameters to be rendered as hidden fields within the form.
be placed
* :form_class - This controls the class of the form within which the submit button will
* :form - This hash will be form attributes
* :data - This option can be used to add custom data attributes.
* :disabled - If set to true, it will generate a disabled button.
:delete, :patch, and :put. By default it will be :post.
* :method - \Symbol of HTTP verb. Supported verbs are :post, :get,

but there are a few special options:
Most values in +html_options+ are passed through to the button element,

#
"
#
#
# => "

<%= button_to "New", false %>

false:
element without an [action] attribute, pass
The +options+ hash accepts the same options as +url_for+. To generate a
==== Options

attribute as described in the +link_to+ documentation.
consider using the +link_to+ method with the +data-turbo-method+
If the HTML button generated from +button_to+ does not work with your layout, you can

To specify a different HTTP verb use the +:method+ option within +html_options+.
conversely, if the object is persisted, it will submit a PATCH request.
The form submits a POST request by default if the object is not persisted;

"button_to" to allow styling of the form and its children.
+:form_class+ option within +html_options+. It defaults to
The class attribute of the form element can be set by passing a

class attribute of the button element.
example, passing a +:class+ option within +html_options+ will set the
values in +html_options+ are passed through to the button element. For
You can control the form and button behavior with +html_options+. Most

cause changes to your data are not triggered by search bots or accelerators.
by the set of +options+. This is the safest method to ensure links that
Generates a form containing a single button that submits to the URL created
def button_to(name = nil, options = nil, html_options = nil, &block)
  html_options, options = options, name if block_given?
  html_options ||= {}
  html_options = html_options.stringify_keys
  url =
    case options
    when FalseClass then nil
    else url_for(options)
    end
  remote = html_options.delete("remote")
  params = html_options.delete("params")
  authenticity_token = html_options.delete("authenticity_token")
  method     = (html_options.delete("method").presence || method_for_options(options)).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[:method] = form_method
  form_options[:action] = url
  form_options[:'data-remote'] = true if remote
  request_token_tag = if form_method == "post"
    request_method = method.empty? ? "post" : method
    token_tag(authenticity_token, form_options: { action: url, method: request_method })
  else
    ""
  end
  html_options = convert_options_to_data_attributes(options, html_options)
  html_options["type"] = "submit"
  button = if block_given?
    content_tag("button", html_options, &block)
  elsif button_to_generates_button_tag
    content_tag("button", name || url, 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
    to_form_params(params).each do |param|
      inner_tags.safe_concat tag(:input, type: "hidden", name: param[:name], value: param[:value],
                                 autocomplete: "off")
    end
  end
  html = content_tag("form", inner_tags, form_options)
  prevent_content_exfiltration(html)
end