aboutsummaryrefslogtreecommitdiffstats
path: root/actionview
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2017-11-14 14:28:02 -0500
committerGitHub <noreply@github.com>2017-11-14 14:28:02 -0500
commit016011551185aee7077f0b9f9635baab568a96a8 (patch)
treee8c90ff0f685e69a827df03217023ca5bb768603 /actionview
parentdf82237a45e930a7ab53b95bee78a3f34c5b92fb (diff)
parentc57e914cd1517013ffdc1fd92f0f705444f26206 (diff)
downloadrails-016011551185aee7077f0b9f9635baab568a96a8.tar.gz
rails-016011551185aee7077f0b9f9635baab568a96a8.tar.bz2
rails-016011551185aee7077f0b9f9635baab568a96a8.zip
Merge pull request #30963 from q-centrix/performance-improvements-add_method_to_attributes
Performance improvements for add_method_to_attributes!
Diffstat (limited to 'actionview')
-rw-r--r--actionview/lib/action_view/helpers/url_helper.rb15
1 files changed, 14 insertions, 1 deletions
diff --git a/actionview/lib/action_view/helpers/url_helper.rb b/actionview/lib/action_view/helpers/url_helper.rb
index 9900e0cd03..02335c72ec 100644
--- a/actionview/lib/action_view/helpers/url_helper.rb
+++ b/actionview/lib/action_view/helpers/url_helper.rb
@@ -589,7 +589,7 @@ module ActionView
end
def add_method_to_attributes!(html_options, method)
- if method && method.to_s.downcase != "get" && html_options["rel"] !~ /nofollow/
+ if method_not_get_method?(method) && html_options["rel"] !~ /nofollow/
if html_options["rel"].blank?
html_options["rel"] = "nofollow"
else
@@ -599,6 +599,19 @@ module ActionView
html_options["data-method"] = method
end
+ STRINGIFIED_COMMON_METHODS = {
+ get: "get",
+ delete: "delete",
+ patch: "patch",
+ post: "post",
+ put: "put",
+ }.freeze
+
+ def method_not_get_method?(method)
+ return false unless method
+ (STRINGIFIED_COMMON_METHODS[method] || method.to_s.downcase) != "get"
+ end
+
def token_tag(token = nil, form_options: {})
if token != false && protect_against_forgery?
token ||= form_authenticity_token(form_options: form_options)