Simplify formmethod checks on button_to for non-GET/POST handling

* Check for the presence of `formmethod` first before checking against
  the GET/POST verbs;
* Use `match?` to avoid creating unnecessary match objects;
* Remove capture groups from the verb regexp.
This commit is contained in:
Carlos Antonio da Silva 2021-02-22 10:00:33 -03:00
parent effed76ec6
commit 3875e07f3c

@ -2546,7 +2546,7 @@ def button(value = nil, options = {}, &block)
end
formmethod = options[:formmethod]
if /(post|get)/i.match(formmethod).nil? && formmethod.present? && !options.key?(:name) && !options.key?(:value)
if formmethod.present? && !/post|get/i.match?(formmethod) && !options.key?(:name) && !options.key?(:value)
options.merge! formmethod: :post, name: "_method", value: formmethod
end