actionpack 7.0.8.1 → 7.2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +94 -500
- data/MIT-LICENSE +1 -1
- data/README.rdoc +2 -2
- data/lib/abstract_controller/asset_paths.rb +2 -0
- data/lib/abstract_controller/base.rb +119 -106
- data/lib/abstract_controller/caching/fragments.rb +51 -52
- data/lib/abstract_controller/caching.rb +2 -0
- data/lib/abstract_controller/callbacks.rb +94 -67
- data/lib/abstract_controller/collector.rb +6 -6
- data/lib/abstract_controller/deprecator.rb +9 -0
- data/lib/abstract_controller/error.rb +2 -0
- data/lib/abstract_controller/helpers.rb +121 -91
- data/lib/abstract_controller/logger.rb +2 -0
- data/lib/abstract_controller/railties/routes_helpers.rb +3 -16
- data/lib/abstract_controller/rendering.rb +14 -13
- data/lib/abstract_controller/translation.rb +12 -30
- data/lib/abstract_controller/url_for.rb +9 -5
- data/lib/abstract_controller.rb +8 -0
- data/lib/action_controller/api/api_rendering.rb +2 -0
- data/lib/action_controller/api.rb +78 -73
- data/lib/action_controller/base.rb +199 -141
- data/lib/action_controller/caching.rb +16 -11
- data/lib/action_controller/deprecator.rb +9 -0
- data/lib/action_controller/form_builder.rb +21 -16
- data/lib/action_controller/log_subscriber.rb +19 -5
- data/lib/action_controller/metal/allow_browser.rb +123 -0
- data/lib/action_controller/metal/basic_implicit_render.rb +2 -0
- data/lib/action_controller/metal/conditional_get.rb +187 -174
- data/lib/action_controller/metal/content_security_policy.rb +26 -25
- data/lib/action_controller/metal/cookies.rb +4 -2
- data/lib/action_controller/metal/data_streaming.rb +65 -54
- data/lib/action_controller/metal/default_headers.rb +6 -2
- data/lib/action_controller/metal/etag_with_flash.rb +4 -0
- data/lib/action_controller/metal/etag_with_template_digest.rb +18 -14
- data/lib/action_controller/metal/exceptions.rb +19 -9
- data/lib/action_controller/metal/flash.rb +12 -10
- data/lib/action_controller/metal/head.rb +20 -16
- data/lib/action_controller/metal/helpers.rb +64 -67
- data/lib/action_controller/metal/http_authentication.rb +214 -200
- data/lib/action_controller/metal/implicit_render.rb +21 -17
- data/lib/action_controller/metal/instrumentation.rb +22 -12
- data/lib/action_controller/metal/live.rb +125 -92
- data/lib/action_controller/metal/logging.rb +6 -4
- data/lib/action_controller/metal/mime_responds.rb +151 -142
- data/lib/action_controller/metal/parameter_encoding.rb +34 -32
- data/lib/action_controller/metal/params_wrapper.rb +58 -58
- data/lib/action_controller/metal/permissions_policy.rb +14 -13
- data/lib/action_controller/metal/rate_limiting.rb +62 -0
- data/lib/action_controller/metal/redirecting.rb +110 -84
- data/lib/action_controller/metal/renderers.rb +50 -49
- data/lib/action_controller/metal/rendering.rb +103 -82
- data/lib/action_controller/metal/request_forgery_protection.rb +279 -161
- data/lib/action_controller/metal/rescue.rb +12 -8
- data/lib/action_controller/metal/streaming.rb +174 -132
- data/lib/action_controller/metal/strong_parameters.rb +598 -473
- data/lib/action_controller/metal/testing.rb +2 -0
- data/lib/action_controller/metal/url_for.rb +23 -14
- data/lib/action_controller/metal.rb +145 -61
- data/lib/action_controller/railtie.rb +25 -9
- data/lib/action_controller/railties/helpers.rb +2 -0
- data/lib/action_controller/renderer.rb +105 -66
- data/lib/action_controller/template_assertions.rb +4 -2
- data/lib/action_controller/test_case.rb +157 -128
- data/lib/action_controller.rb +17 -3
- data/lib/action_dispatch/constants.rb +34 -0
- data/lib/action_dispatch/deprecator.rb +9 -0
- data/lib/action_dispatch/http/cache.rb +28 -29
- data/lib/action_dispatch/http/content_disposition.rb +2 -0
- data/lib/action_dispatch/http/content_security_policy.rb +69 -49
- data/lib/action_dispatch/http/filter_parameters.rb +27 -12
- data/lib/action_dispatch/http/filter_redirect.rb +22 -1
- data/lib/action_dispatch/http/headers.rb +23 -21
- data/lib/action_dispatch/http/mime_negotiation.rb +37 -48
- data/lib/action_dispatch/http/mime_type.rb +60 -30
- data/lib/action_dispatch/http/mime_types.rb +5 -1
- data/lib/action_dispatch/http/parameters.rb +12 -10
- data/lib/action_dispatch/http/permissions_policy.rb +32 -34
- data/lib/action_dispatch/http/rack_cache.rb +4 -0
- data/lib/action_dispatch/http/request.rb +132 -79
- data/lib/action_dispatch/http/response.rb +136 -103
- data/lib/action_dispatch/http/upload.rb +19 -15
- data/lib/action_dispatch/http/url.rb +75 -73
- data/lib/action_dispatch/journey/formatter.rb +19 -6
- data/lib/action_dispatch/journey/gtg/builder.rb +4 -3
- data/lib/action_dispatch/journey/gtg/simulator.rb +2 -0
- data/lib/action_dispatch/journey/gtg/transition_table.rb +10 -8
- data/lib/action_dispatch/journey/nfa/dot.rb +2 -0
- data/lib/action_dispatch/journey/nodes/node.rb +6 -5
- data/lib/action_dispatch/journey/parser.rb +4 -3
- data/lib/action_dispatch/journey/parser_extras.rb +2 -0
- data/lib/action_dispatch/journey/path/pattern.rb +18 -15
- data/lib/action_dispatch/journey/route.rb +12 -9
- data/lib/action_dispatch/journey/router/utils.rb +16 -15
- data/lib/action_dispatch/journey/router.rb +13 -10
- data/lib/action_dispatch/journey/routes.rb +6 -4
- data/lib/action_dispatch/journey/scanner.rb +4 -2
- data/lib/action_dispatch/journey/visitors.rb +2 -0
- data/lib/action_dispatch/journey.rb +2 -0
- data/lib/action_dispatch/log_subscriber.rb +25 -0
- data/lib/action_dispatch/middleware/actionable_exceptions.rb +7 -6
- data/lib/action_dispatch/middleware/assume_ssl.rb +27 -0
- data/lib/action_dispatch/middleware/callbacks.rb +4 -0
- data/lib/action_dispatch/middleware/cookies.rb +192 -194
- data/lib/action_dispatch/middleware/debug_exceptions.rb +36 -27
- data/lib/action_dispatch/middleware/debug_locks.rb +18 -13
- data/lib/action_dispatch/middleware/debug_view.rb +9 -2
- data/lib/action_dispatch/middleware/exception_wrapper.rb +181 -27
- data/lib/action_dispatch/middleware/executor.rb +9 -1
- data/lib/action_dispatch/middleware/flash.rb +65 -46
- data/lib/action_dispatch/middleware/host_authorization.rb +22 -17
- data/lib/action_dispatch/middleware/public_exceptions.rb +12 -8
- data/lib/action_dispatch/middleware/reloader.rb +9 -5
- data/lib/action_dispatch/middleware/remote_ip.rb +88 -83
- data/lib/action_dispatch/middleware/request_id.rb +15 -8
- data/lib/action_dispatch/middleware/server_timing.rb +8 -6
- data/lib/action_dispatch/middleware/session/abstract_store.rb +7 -0
- data/lib/action_dispatch/middleware/session/cache_store.rb +14 -7
- data/lib/action_dispatch/middleware/session/cookie_store.rb +32 -25
- data/lib/action_dispatch/middleware/session/mem_cache_store.rb +9 -3
- data/lib/action_dispatch/middleware/show_exceptions.rb +42 -28
- data/lib/action_dispatch/middleware/ssl.rb +60 -45
- data/lib/action_dispatch/middleware/stack.rb +15 -9
- data/lib/action_dispatch/middleware/static.rb +40 -34
- data/lib/action_dispatch/middleware/templates/rescues/_actions.html.erb +2 -2
- data/lib/action_dispatch/middleware/templates/rescues/_message_and_suggestions.html.erb +4 -4
- data/lib/action_dispatch/middleware/templates/rescues/_source.html.erb +8 -1
- data/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb +7 -7
- data/lib/action_dispatch/middleware/templates/rescues/diagnostics.text.erb +2 -2
- data/lib/action_dispatch/middleware/templates/rescues/layout.erb +17 -0
- data/lib/action_dispatch/middleware/templates/rescues/missing_exact_template.html.erb +16 -12
- data/lib/action_dispatch/middleware/templates/rescues/missing_template.html.erb +1 -1
- data/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb +3 -3
- data/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb +4 -4
- data/lib/action_dispatch/middleware/templates/rescues/unknown_action.html.erb +1 -1
- data/lib/action_dispatch/middleware/templates/rescues/unknown_action.text.erb +1 -1
- data/lib/action_dispatch/middleware/templates/routes/_route.html.erb +3 -0
- data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +47 -38
- data/lib/action_dispatch/railtie.rb +12 -4
- data/lib/action_dispatch/request/session.rb +39 -27
- data/lib/action_dispatch/request/utils.rb +10 -3
- data/lib/action_dispatch/routing/endpoint.rb +2 -0
- data/lib/action_dispatch/routing/inspector.rb +59 -9
- data/lib/action_dispatch/routing/mapper.rb +686 -639
- data/lib/action_dispatch/routing/polymorphic_routes.rb +70 -61
- data/lib/action_dispatch/routing/redirection.rb +52 -38
- data/lib/action_dispatch/routing/route_set.rb +106 -62
- data/lib/action_dispatch/routing/routes_proxy.rb +16 -19
- data/lib/action_dispatch/routing/url_for.rb +131 -122
- data/lib/action_dispatch/routing.rb +152 -150
- data/lib/action_dispatch/system_test_case.rb +91 -81
- data/lib/action_dispatch/system_testing/browser.rb +27 -19
- data/lib/action_dispatch/system_testing/driver.rb +16 -22
- data/lib/action_dispatch/system_testing/server.rb +2 -0
- data/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb +53 -31
- data/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb +2 -0
- data/lib/action_dispatch/testing/assertion_response.rb +9 -7
- data/lib/action_dispatch/testing/assertions/response.rb +36 -26
- data/lib/action_dispatch/testing/assertions/routing.rb +203 -95
- data/lib/action_dispatch/testing/assertions.rb +5 -1
- data/lib/action_dispatch/testing/integration.rb +240 -229
- data/lib/action_dispatch/testing/request_encoder.rb +6 -1
- data/lib/action_dispatch/testing/test_helpers/page_dump_helper.rb +35 -0
- data/lib/action_dispatch/testing/test_process.rb +14 -9
- data/lib/action_dispatch/testing/test_request.rb +4 -2
- data/lib/action_dispatch/testing/test_response.rb +34 -19
- data/lib/action_dispatch.rb +52 -21
- data/lib/action_pack/gem_version.rb +5 -3
- data/lib/action_pack/version.rb +3 -1
- data/lib/action_pack.rb +18 -17
- metadata +91 -32
@@ -1,57 +1,64 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# :markup: markdown
|
4
|
+
|
3
5
|
module ActionController
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
6
|
+
# # Action Controller Helpers
|
7
|
+
#
|
8
|
+
# The Rails framework provides a large number of helpers for working with
|
9
|
+
# assets, dates, forms, numbers and model objects, to name a few. These helpers
|
10
|
+
# are available to all templates by default.
|
7
11
|
#
|
8
|
-
# In addition to using the standard template helpers provided, creating custom
|
9
|
-
# extract complicated logic or reusable functionality is strongly
|
10
|
-
# will include all helpers. These
|
12
|
+
# In addition to using the standard template helpers provided, creating custom
|
13
|
+
# helpers to extract complicated logic or reusable functionality is strongly
|
14
|
+
# encouraged. By default, each controller will include all helpers. These
|
15
|
+
# helpers are only accessible on the controller through `#helpers`
|
11
16
|
#
|
12
|
-
# In previous versions of
|
13
|
-
# matches the name of the controller, e.g.,
|
14
|
-
# include
|
17
|
+
# In previous versions of Rails the controller will include a helper which
|
18
|
+
# matches the name of the controller, e.g., `MyController` will automatically
|
19
|
+
# include `MyHelper`. You can revert to the old behavior with the following:
|
15
20
|
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
21
|
+
# # config/application.rb
|
22
|
+
# class Application < Rails::Application
|
23
|
+
# config.action_controller.include_all_helpers = false
|
24
|
+
# end
|
20
25
|
#
|
21
|
-
# Additional helpers can be specified using the
|
22
|
-
# controller which inherits from it.
|
26
|
+
# Additional helpers can be specified using the `helper` class method in
|
27
|
+
# ActionController::Base or any controller which inherits from it.
|
23
28
|
#
|
24
|
-
# The
|
25
|
-
# a
|
29
|
+
# The `to_s` method from the Time class can be wrapped in a helper method to
|
30
|
+
# display a custom message if a Time object is blank:
|
26
31
|
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
32
|
+
# module FormattedTimeHelper
|
33
|
+
# def format_time(time, format=:long, blank_message=" ")
|
34
|
+
# time.blank? ? blank_message : time.to_fs(format)
|
35
|
+
# end
|
30
36
|
# end
|
31
|
-
# end
|
32
37
|
#
|
33
|
-
# FormattedTimeHelper can now be included in a controller, using the
|
38
|
+
# FormattedTimeHelper can now be included in a controller, using the `helper`
|
39
|
+
# class method:
|
34
40
|
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
#
|
41
|
+
# class EventsController < ActionController::Base
|
42
|
+
# helper FormattedTimeHelper
|
43
|
+
# def index
|
44
|
+
# @events = Event.all
|
45
|
+
# end
|
39
46
|
# end
|
40
|
-
# end
|
41
47
|
#
|
42
|
-
# Then, in any view rendered by
|
48
|
+
# Then, in any view rendered by `EventsController`, the `format_time` method can
|
49
|
+
# be called:
|
43
50
|
#
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
51
|
+
# <% @events.each do |event| -%>
|
52
|
+
# <p>
|
53
|
+
# <%= format_time(event.time, :short, "N/A") %> | <%= event.name %>
|
54
|
+
# </p>
|
55
|
+
# <% end -%>
|
49
56
|
#
|
50
|
-
# Finally, assuming we have two event instances, one which has a time and one
|
51
|
-
# the output might look like this:
|
57
|
+
# Finally, assuming we have two event instances, one which has a time and one
|
58
|
+
# which does not, the output might look like this:
|
52
59
|
#
|
53
|
-
#
|
54
|
-
#
|
60
|
+
# 23 Aug 11:30 | Carolina Railhawks Soccer Match
|
61
|
+
# N/A | Carolina Railhawks Training Workshop
|
55
62
|
#
|
56
63
|
module Helpers
|
57
64
|
extend ActiveSupport::Concern
|
@@ -66,23 +73,24 @@ module ActionController
|
|
66
73
|
|
67
74
|
module ClassMethods
|
68
75
|
# Declares helper accessors for controller attributes. For example, the
|
69
|
-
# following adds new
|
70
|
-
#
|
71
|
-
#
|
72
|
-
#
|
76
|
+
# following adds new `name` and `name=` instance methods to a controller and
|
77
|
+
# makes them available to the view:
|
78
|
+
# attr_accessor :name
|
79
|
+
# helper_attr :name
|
80
|
+
#
|
81
|
+
# #### Parameters
|
82
|
+
# * `attrs` - Names of attributes to be converted into helpers.
|
73
83
|
#
|
74
|
-
# ==== Parameters
|
75
|
-
# * <tt>attrs</tt> - Names of attributes to be converted into helpers.
|
76
84
|
def helper_attr(*attrs)
|
77
85
|
attrs.flatten.each { |attr| helper_method(attr, "#{attr}=") }
|
78
86
|
end
|
79
87
|
|
80
88
|
# Provides a proxy to access helper methods from outside the view.
|
81
89
|
#
|
82
|
-
# Note that the proxy is rendered under a different view context.
|
83
|
-
#
|
84
|
-
#
|
85
|
-
#
|
90
|
+
# Note that the proxy is rendered under a different view context. This may cause
|
91
|
+
# incorrect behavior with capture methods. Consider using
|
92
|
+
# [helper](rdoc-ref:AbstractController::Helpers::ClassMethods#helper) instead
|
93
|
+
# when using `capture`.
|
86
94
|
def helpers
|
87
95
|
@helper_proxy ||= begin
|
88
96
|
proxy = ActionView::Base.empty
|
@@ -91,34 +99,23 @@ module ActionController
|
|
91
99
|
end
|
92
100
|
end
|
93
101
|
|
94
|
-
# Override modules_for_helpers to accept
|
95
|
-
#
|
102
|
+
# Override modules_for_helpers to accept `:all` as argument, which loads all
|
103
|
+
# helpers in helpers_path.
|
104
|
+
#
|
105
|
+
# #### Parameters
|
106
|
+
# * `args` - A list of helpers
|
96
107
|
#
|
97
|
-
# ==== Parameters
|
98
|
-
# * <tt>args</tt> - A list of helpers
|
99
108
|
#
|
100
|
-
#
|
101
|
-
# *
|
109
|
+
# #### Returns
|
110
|
+
# * `array` - A normalized list of modules for the list of helpers provided.
|
111
|
+
#
|
102
112
|
def modules_for_helpers(args)
|
103
113
|
args += all_application_helpers if args.delete(:all)
|
104
114
|
super(args)
|
105
115
|
end
|
106
116
|
|
107
|
-
# Returns a list of helper names in a given path.
|
108
|
-
#
|
109
|
-
# ActionController::Base.all_helpers_from_path 'app/helpers'
|
110
|
-
# # => ["application", "chart", "rubygems"]
|
111
|
-
def all_helpers_from_path(path)
|
112
|
-
helpers = Array(path).flat_map do |_path|
|
113
|
-
names = Dir["#{_path}/**/*_helper.rb"].map { |file| file[_path.to_s.size + 1..-"_helper.rb".size - 1] }
|
114
|
-
names.sort!
|
115
|
-
end
|
116
|
-
helpers.uniq!
|
117
|
-
helpers
|
118
|
-
end
|
119
|
-
|
120
117
|
private
|
121
|
-
# Extract helper names from files in
|
118
|
+
# Extract helper names from files in `app/helpers/***/**_helper.rb`
|
122
119
|
def all_application_helpers
|
123
120
|
all_helpers_from_path(helpers_path)
|
124
121
|
end
|