module ActionView::Helpers::UrlHelper

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


# "
#
#
# => "

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

===== Rails UJS Examples

button when the form is submitted.
used as the value for a disabled version of the submit
* :disable_with - Value of this parameter will be
button is processed normally, otherwise no action is taken.
resulting text would be question?). If the user accepts, the
to prompt with the question specified (in this case, the
* confirm: "question?" - This will allow @rails/ujs

@rails/ujs also integrated with the following +:data+ options:

submit behavior. By default this behavior is an Ajax submit.
* :remote - If set to true, will allow @rails/ujs to control the

this library is no longer on by default. This library integrated with the following options:
Prior to Rails 7, Rails shipped with a JavaScript library called @rails/ujs on by default. Following Rails 7,

==== Deprecated: Rails UJS Attributes

#
"
#
#
# => "

<%= 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

HTTP verb via the +:method+ option within +html_options+.
The form submits a POST request by default. You can specify a different

"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

the +link_to+ documentation.
using the +link_to+ method with the :method modifier as described in
If the HTML button does not work with your layout, you can also consider
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
  content_tag("form", inner_tags, form_options)
end