actionpack 7.1.5.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 +76 -604
- data/lib/abstract_controller/asset_paths.rb +2 -0
- data/lib/abstract_controller/base.rb +102 -98
- data/lib/abstract_controller/caching/fragments.rb +50 -53
- data/lib/abstract_controller/caching.rb +2 -0
- data/lib/abstract_controller/callbacks.rb +66 -64
- data/lib/abstract_controller/collector.rb +6 -6
- data/lib/abstract_controller/deprecator.rb +2 -0
- data/lib/abstract_controller/error.rb +2 -0
- data/lib/abstract_controller/helpers.rb +72 -85
- data/lib/abstract_controller/logger.rb +2 -0
- data/lib/abstract_controller/railties/routes_helpers.rb +2 -0
- data/lib/abstract_controller/rendering.rb +13 -12
- data/lib/abstract_controller/translation.rb +12 -13
- data/lib/abstract_controller/url_for.rb +8 -6
- data/lib/abstract_controller.rb +2 -0
- data/lib/action_controller/api/api_rendering.rb +2 -0
- data/lib/action_controller/api.rb +75 -72
- data/lib/action_controller/base.rb +198 -126
- data/lib/action_controller/caching.rb +15 -12
- data/lib/action_controller/deprecator.rb +2 -0
- data/lib/action_controller/form_builder.rb +20 -17
- data/lib/action_controller/log_subscriber.rb +3 -1
- 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 +25 -24
- data/lib/action_controller/metal/cookies.rb +4 -2
- data/lib/action_controller/metal/data_streaming.rb +64 -55
- data/lib/action_controller/metal/default_headers.rb +5 -3
- data/lib/action_controller/metal/etag_with_flash.rb +3 -1
- data/lib/action_controller/metal/etag_with_template_digest.rb +17 -15
- data/lib/action_controller/metal/exceptions.rb +11 -9
- data/lib/action_controller/metal/flash.rb +12 -10
- data/lib/action_controller/metal/head.rb +12 -10
- data/lib/action_controller/metal/helpers.rb +63 -55
- data/lib/action_controller/metal/http_authentication.rb +209 -201
- data/lib/action_controller/metal/implicit_render.rb +17 -15
- data/lib/action_controller/metal/instrumentation.rb +15 -12
- data/lib/action_controller/metal/live.rb +116 -107
- 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 +57 -59
- data/lib/action_controller/metal/permissions_policy.rb +13 -12
- data/lib/action_controller/metal/rate_limiting.rb +62 -0
- data/lib/action_controller/metal/redirecting.rb +108 -82
- data/lib/action_controller/metal/renderers.rb +50 -49
- data/lib/action_controller/metal/rendering.rb +103 -75
- data/lib/action_controller/metal/request_forgery_protection.rb +162 -133
- data/lib/action_controller/metal/rescue.rb +11 -9
- data/lib/action_controller/metal/streaming.rb +138 -136
- data/lib/action_controller/metal/strong_parameters.rb +483 -478
- data/lib/action_controller/metal/testing.rb +2 -0
- data/lib/action_controller/metal/url_for.rb +17 -15
- data/lib/action_controller/metal.rb +86 -60
- data/lib/action_controller/railtie.rb +3 -0
- data/lib/action_controller/railties/helpers.rb +2 -0
- data/lib/action_controller/renderer.rb +42 -36
- data/lib/action_controller/template_assertions.rb +4 -2
- data/lib/action_controller/test_case.rb +148 -129
- data/lib/action_controller.rb +5 -1
- data/lib/action_dispatch/constants.rb +2 -0
- data/lib/action_dispatch/deprecator.rb +2 -0
- data/lib/action_dispatch/http/cache.rb +27 -26
- data/lib/action_dispatch/http/content_disposition.rb +2 -0
- data/lib/action_dispatch/http/content_security_policy.rb +40 -38
- data/lib/action_dispatch/http/filter_parameters.rb +9 -5
- data/lib/action_dispatch/http/filter_redirect.rb +22 -1
- data/lib/action_dispatch/http/headers.rb +22 -22
- data/lib/action_dispatch/http/mime_negotiation.rb +30 -41
- data/lib/action_dispatch/http/mime_type.rb +25 -21
- data/lib/action_dispatch/http/mime_types.rb +2 -0
- data/lib/action_dispatch/http/parameters.rb +11 -9
- data/lib/action_dispatch/http/permissions_policy.rb +19 -36
- data/lib/action_dispatch/http/rack_cache.rb +2 -0
- data/lib/action_dispatch/http/request.rb +70 -71
- data/lib/action_dispatch/http/response.rb +73 -61
- data/lib/action_dispatch/http/upload.rb +18 -16
- data/lib/action_dispatch/http/url.rb +75 -73
- data/lib/action_dispatch/journey/formatter.rb +13 -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 +4 -1
- data/lib/action_dispatch/journey/route.rb +9 -7
- data/lib/action_dispatch/journey/router/utils.rb +16 -15
- data/lib/action_dispatch/journey/router.rb +4 -2
- data/lib/action_dispatch/journey/routes.rb +4 -2
- 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 +2 -0
- data/lib/action_dispatch/middleware/actionable_exceptions.rb +2 -0
- data/lib/action_dispatch/middleware/assume_ssl.rb +8 -5
- data/lib/action_dispatch/middleware/callbacks.rb +3 -1
- data/lib/action_dispatch/middleware/cookies.rb +119 -104
- data/lib/action_dispatch/middleware/debug_exceptions.rb +13 -5
- data/lib/action_dispatch/middleware/debug_locks.rb +15 -13
- data/lib/action_dispatch/middleware/debug_view.rb +2 -0
- data/lib/action_dispatch/middleware/exception_wrapper.rb +6 -11
- data/lib/action_dispatch/middleware/executor.rb +2 -0
- data/lib/action_dispatch/middleware/flash.rb +63 -51
- data/lib/action_dispatch/middleware/host_authorization.rb +17 -15
- data/lib/action_dispatch/middleware/public_exceptions.rb +8 -6
- data/lib/action_dispatch/middleware/reloader.rb +5 -3
- data/lib/action_dispatch/middleware/remote_ip.rb +76 -72
- data/lib/action_dispatch/middleware/request_id.rb +14 -9
- data/lib/action_dispatch/middleware/server_timing.rb +4 -2
- data/lib/action_dispatch/middleware/session/abstract_store.rb +2 -0
- data/lib/action_dispatch/middleware/session/cache_store.rb +13 -8
- data/lib/action_dispatch/middleware/session/cookie_store.rb +27 -26
- data/lib/action_dispatch/middleware/session/mem_cache_store.rb +7 -3
- data/lib/action_dispatch/middleware/show_exceptions.rb +16 -16
- data/lib/action_dispatch/middleware/ssl.rb +43 -40
- data/lib/action_dispatch/middleware/stack.rb +11 -10
- data/lib/action_dispatch/middleware/static.rb +33 -31
- data/lib/action_dispatch/middleware/templates/rescues/_source.html.erb +1 -1
- data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +1 -1
- data/lib/action_dispatch/railtie.rb +2 -3
- data/lib/action_dispatch/request/session.rb +23 -21
- data/lib/action_dispatch/request/utils.rb +2 -0
- data/lib/action_dispatch/routing/endpoint.rb +2 -0
- data/lib/action_dispatch/routing/inspector.rb +5 -3
- data/lib/action_dispatch/routing/mapper.rb +622 -623
- data/lib/action_dispatch/routing/polymorphic_routes.rb +69 -62
- data/lib/action_dispatch/routing/redirection.rb +37 -32
- data/lib/action_dispatch/routing/route_set.rb +59 -45
- data/lib/action_dispatch/routing/routes_proxy.rb +6 -4
- data/lib/action_dispatch/routing/url_for.rb +130 -125
- data/lib/action_dispatch/routing.rb +150 -148
- data/lib/action_dispatch/system_test_case.rb +91 -81
- data/lib/action_dispatch/system_testing/browser.rb +4 -2
- data/lib/action_dispatch/system_testing/driver.rb +2 -0
- data/lib/action_dispatch/system_testing/server.rb +2 -0
- data/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb +32 -21
- data/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb +2 -0
- data/lib/action_dispatch/testing/assertion_response.rb +8 -6
- data/lib/action_dispatch/testing/assertions/response.rb +26 -23
- data/lib/action_dispatch/testing/assertions/routing.rb +153 -84
- data/lib/action_dispatch/testing/assertions.rb +2 -0
- data/lib/action_dispatch/testing/integration.rb +223 -222
- data/lib/action_dispatch/testing/request_encoder.rb +2 -0
- data/lib/action_dispatch/testing/test_helpers/page_dump_helper.rb +35 -0
- data/lib/action_dispatch/testing/test_process.rb +12 -8
- data/lib/action_dispatch/testing/test_request.rb +3 -1
- data/lib/action_dispatch/testing/test_response.rb +27 -26
- data/lib/action_dispatch.rb +22 -28
- data/lib/action_pack/gem_version.rb +5 -3
- data/lib/action_pack/version.rb +3 -1
- data/lib/action_pack.rb +17 -16
- metadata +34 -11
@@ -1,170 +1,208 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# :markup: markdown
|
4
|
+
|
3
5
|
require "action_view"
|
4
6
|
require "action_controller/log_subscriber"
|
5
7
|
require "action_controller/metal/params_wrapper"
|
6
8
|
|
7
9
|
module ActionController
|
8
|
-
#
|
10
|
+
# # Action Controller Base
|
9
11
|
#
|
10
|
-
# Action Controllers are the core of a web request in
|
11
|
-
# on request and then either it renders a
|
12
|
-
#
|
12
|
+
# Action Controllers are the core of a web request in Rails. They are made up of
|
13
|
+
# one or more actions that are executed on request and then either it renders a
|
14
|
+
# template or redirects to another action. An action is defined as a public
|
15
|
+
# method on the controller, which will automatically be made accessible to the
|
16
|
+
# web-server through Rails Routes.
|
13
17
|
#
|
14
|
-
# By default, only the ApplicationController in a
|
15
|
-
#
|
18
|
+
# By default, only the ApplicationController in a Rails application inherits
|
19
|
+
# from `ActionController::Base`. All other controllers inherit from
|
20
|
+
# ApplicationController. This gives you one class to configure things such as
|
16
21
|
# request forgery protection and filtering of sensitive request parameters.
|
17
22
|
#
|
18
23
|
# A sample controller could look like this:
|
19
24
|
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
25
|
+
# class PostsController < ApplicationController
|
26
|
+
# def index
|
27
|
+
# @posts = Post.all
|
28
|
+
# end
|
24
29
|
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
30
|
+
# def create
|
31
|
+
# @post = Post.create params[:post]
|
32
|
+
# redirect_to posts_path
|
33
|
+
# end
|
28
34
|
# end
|
29
|
-
# end
|
30
35
|
#
|
31
|
-
# Actions, by default, render a template in the
|
32
|
-
#
|
33
|
-
#
|
36
|
+
# Actions, by default, render a template in the `app/views` directory
|
37
|
+
# corresponding to the name of the controller and action after executing code in
|
38
|
+
# the action. For example, the `index` action of the PostsController would
|
39
|
+
# render the template `app/views/posts/index.html.erb` by default after
|
40
|
+
# populating the `@posts` instance variable.
|
34
41
|
#
|
35
|
-
# Unlike index, the create action will not render a template. After performing
|
36
|
-
# new post), it initiates a redirect instead. This
|
37
|
-
#
|
42
|
+
# Unlike index, the create action will not render a template. After performing
|
43
|
+
# its main purpose (creating a new post), it initiates a redirect instead. This
|
44
|
+
# redirect works by returning an external `302 Moved` HTTP response that takes
|
45
|
+
# the user to the index action.
|
38
46
|
#
|
39
|
-
# These two methods represent the two basic action archetypes used in Action
|
40
|
-
# Most actions are variations on
|
47
|
+
# These two methods represent the two basic action archetypes used in Action
|
48
|
+
# Controllers: Get-and-show and do-and-redirect. Most actions are variations on
|
49
|
+
# these themes.
|
41
50
|
#
|
42
|
-
#
|
51
|
+
# ## Requests
|
43
52
|
#
|
44
|
-
# For every request, the router determines the value of the
|
45
|
-
#
|
46
|
-
#
|
53
|
+
# For every request, the router determines the value of the `controller` and
|
54
|
+
# `action` keys. These determine which controller and action are called. The
|
55
|
+
# remaining request parameters, the session (if one is available), and the full
|
56
|
+
# request with all the HTTP headers are made available to the action through
|
57
|
+
# accessor methods. Then the action is performed.
|
47
58
|
#
|
48
|
-
# The full request object is available via the request accessor and is primarily
|
59
|
+
# The full request object is available via the request accessor and is primarily
|
60
|
+
# used to query for HTTP headers:
|
49
61
|
#
|
50
|
-
#
|
51
|
-
#
|
52
|
-
#
|
53
|
-
#
|
62
|
+
# def server_ip
|
63
|
+
# location = request.env["REMOTE_ADDR"]
|
64
|
+
# render plain: "This server hosted at #{location}"
|
65
|
+
# end
|
54
66
|
#
|
55
|
-
#
|
67
|
+
# ## Parameters
|
56
68
|
#
|
57
|
-
# All request parameters, whether they come from a query string in the URL or
|
58
|
-
#
|
59
|
-
#
|
69
|
+
# All request parameters, whether they come from a query string in the URL or
|
70
|
+
# form data submitted through a POST request are available through the `params`
|
71
|
+
# method which returns a hash. For example, an action that was performed through
|
72
|
+
# `/posts?category=All&limit=5` will include `{ "category" => "All", "limit" =>
|
73
|
+
# "5" }` in `params`.
|
60
74
|
#
|
61
|
-
# It's also possible to construct multi-dimensional parameter hashes by
|
75
|
+
# It's also possible to construct multi-dimensional parameter hashes by
|
76
|
+
# specifying keys using brackets, such as:
|
62
77
|
#
|
63
|
-
#
|
64
|
-
#
|
78
|
+
# <input type="text" name="post[name]" value="david">
|
79
|
+
# <input type="text" name="post[address]" value="hyacintvej">
|
65
80
|
#
|
66
|
-
# A request coming from a form holding these inputs will include
|
67
|
-
#
|
68
|
-
#
|
81
|
+
# A request coming from a form holding these inputs will include `{ "post" => {
|
82
|
+
# "name" => "david", "address" => "hyacintvej" } }`. If the address input had
|
83
|
+
# been named `post[address][street]`, the `params` would have included `{ "post"
|
84
|
+
# => { "address" => { "street" => "hyacintvej" } } }`. There's no limit to the
|
85
|
+
# depth of the nesting.
|
69
86
|
#
|
70
|
-
#
|
87
|
+
# ## Sessions
|
71
88
|
#
|
72
|
-
# Sessions allow you to store objects in between requests. This is useful for
|
73
|
-
#
|
74
|
-
#
|
75
|
-
#
|
89
|
+
# Sessions allow you to store objects in between requests. This is useful for
|
90
|
+
# objects that are not yet ready to be persisted, such as a Signup object
|
91
|
+
# constructed in a multi-paged process, or objects that don't change much and
|
92
|
+
# are needed all the time, such as a User object for a system that requires
|
93
|
+
# login. The session should not be used, however, as a cache for objects where
|
94
|
+
# it's likely they could be changed unknowingly. It's usually too much work to
|
95
|
+
# keep it all synchronized -- something databases already excel at.
|
76
96
|
#
|
77
|
-
# You can place objects in the session by using the
|
97
|
+
# You can place objects in the session by using the `session` method, which
|
98
|
+
# accesses a hash:
|
78
99
|
#
|
79
|
-
#
|
100
|
+
# session[:person] = Person.authenticate(user_name, password)
|
80
101
|
#
|
81
102
|
# You can retrieve it again through the same hash:
|
82
103
|
#
|
83
|
-
#
|
104
|
+
# "Hello #{session[:person]}"
|
84
105
|
#
|
85
|
-
# For removing objects from the session, you can either assign a single key to
|
106
|
+
# For removing objects from the session, you can either assign a single key to
|
107
|
+
# `nil`:
|
86
108
|
#
|
87
|
-
#
|
88
|
-
#
|
109
|
+
# # removes :person from session
|
110
|
+
# session[:person] = nil
|
89
111
|
#
|
90
|
-
# or you can remove the entire session with
|
112
|
+
# or you can remove the entire session with `reset_session`.
|
91
113
|
#
|
92
114
|
# By default, sessions are stored in an encrypted browser cookie (see
|
93
|
-
# ActionDispatch::Session::CookieStore). Thus the user will not be able to
|
94
|
-
#
|
95
|
-
#
|
96
|
-
#
|
115
|
+
# ActionDispatch::Session::CookieStore). Thus the user will not be able to read
|
116
|
+
# or edit the session data. However, the user can keep a copy of the cookie even
|
117
|
+
# after it has expired, so you should avoid storing sensitive information in
|
118
|
+
# cookie-based sessions.
|
97
119
|
#
|
98
|
-
#
|
120
|
+
# ## Responses
|
99
121
|
#
|
100
|
-
# Each action results in a response, which holds the headers and document to be
|
101
|
-
#
|
122
|
+
# Each action results in a response, which holds the headers and document to be
|
123
|
+
# sent to the user's browser. The actual response object is generated
|
124
|
+
# automatically through the use of renders and redirects and requires no user
|
125
|
+
# intervention.
|
102
126
|
#
|
103
|
-
#
|
127
|
+
# ## Renders
|
104
128
|
#
|
105
|
-
# Action Controller sends content to the user by using one of five rendering
|
106
|
-
#
|
107
|
-
#
|
129
|
+
# Action Controller sends content to the user by using one of five rendering
|
130
|
+
# methods. The most versatile and common is the rendering of a template.
|
131
|
+
# Included in the Action Pack is the Action View, which enables rendering of ERB
|
132
|
+
# templates. It's automatically configured. The controller passes objects to the
|
133
|
+
# view by assigning instance variables:
|
108
134
|
#
|
109
|
-
#
|
110
|
-
#
|
111
|
-
#
|
135
|
+
# def show
|
136
|
+
# @post = Post.find(params[:id])
|
137
|
+
# end
|
112
138
|
#
|
113
139
|
# Which are then automatically available to the view:
|
114
140
|
#
|
115
|
-
#
|
141
|
+
# Title: <%= @post.title %>
|
116
142
|
#
|
117
|
-
# You don't have to rely on the automated rendering. For example, actions that
|
118
|
-
# will use the manual
|
143
|
+
# You don't have to rely on the automated rendering. For example, actions that
|
144
|
+
# could result in the rendering of different templates will use the manual
|
145
|
+
# rendering methods:
|
119
146
|
#
|
120
|
-
#
|
121
|
-
#
|
122
|
-
#
|
123
|
-
#
|
124
|
-
#
|
125
|
-
#
|
147
|
+
# def search
|
148
|
+
# @results = Search.find(params[:query])
|
149
|
+
# case @results.count
|
150
|
+
# when 0 then render action: "no_results"
|
151
|
+
# when 1 then render action: "show"
|
152
|
+
# when 2..10 then render action: "show_many"
|
153
|
+
# end
|
126
154
|
# end
|
127
|
-
# end
|
128
155
|
#
|
129
156
|
# Read more about writing ERB and Builder templates in ActionView::Base.
|
130
157
|
#
|
131
|
-
#
|
158
|
+
# ## Redirects
|
132
159
|
#
|
133
|
-
# Redirects are used to move from one action to another. For example, after a
|
134
|
-
#
|
135
|
-
#
|
160
|
+
# Redirects are used to move from one action to another. For example, after a
|
161
|
+
# `create` action, which stores a blog entry to the database, we might like to
|
162
|
+
# show the user the new entry. Because we're following good DRY principles
|
163
|
+
# (Don't Repeat Yourself), we're going to reuse (and redirect to) a `show`
|
164
|
+
# action that we'll assume has already been created. The code might look like
|
165
|
+
# this:
|
136
166
|
#
|
137
|
-
#
|
138
|
-
#
|
139
|
-
#
|
140
|
-
#
|
141
|
-
#
|
142
|
-
#
|
143
|
-
#
|
167
|
+
# def create
|
168
|
+
# @entry = Entry.new(params[:entry])
|
169
|
+
# if @entry.save
|
170
|
+
# # The entry was saved correctly, redirect to show
|
171
|
+
# redirect_to action: 'show', id: @entry.id
|
172
|
+
# else
|
173
|
+
# # things didn't go so well, do something else
|
174
|
+
# end
|
144
175
|
# end
|
145
|
-
# end
|
146
176
|
#
|
147
|
-
# In this case, after saving our new entry to the database, the user is
|
148
|
-
#
|
149
|
-
#
|
177
|
+
# In this case, after saving our new entry to the database, the user is
|
178
|
+
# redirected to the `show` method, which is then executed. Note that this is an
|
179
|
+
# external HTTP-level redirection which will cause the browser to make a second
|
180
|
+
# request (a GET to the show action), and not some internal re-routing which
|
181
|
+
# calls both "create" and then "show" within one request.
|
150
182
|
#
|
151
|
-
# Learn more about
|
183
|
+
# Learn more about `redirect_to` and what options you have in
|
184
|
+
# ActionController::Redirecting.
|
152
185
|
#
|
153
|
-
#
|
186
|
+
# ## Calling multiple redirects or renders
|
154
187
|
#
|
155
|
-
# An action may
|
188
|
+
# An action may perform only a single render or a single redirect. Attempting to
|
189
|
+
# do either again will result in a DoubleRenderError:
|
156
190
|
#
|
157
|
-
#
|
158
|
-
#
|
159
|
-
#
|
160
|
-
#
|
191
|
+
# def do_something
|
192
|
+
# redirect_to action: "elsewhere"
|
193
|
+
# render action: "overthere" # raises DoubleRenderError
|
194
|
+
# end
|
161
195
|
#
|
162
|
-
# If you need to redirect on the condition of something, then be sure to add
|
196
|
+
# If you need to redirect on the condition of something, then be sure to add
|
197
|
+
# "return" to halt execution.
|
163
198
|
#
|
164
|
-
#
|
165
|
-
#
|
166
|
-
#
|
167
|
-
#
|
199
|
+
# def do_something
|
200
|
+
# if monkeys.nil?
|
201
|
+
# redirect_to(action: "elsewhere")
|
202
|
+
# return
|
203
|
+
# end
|
204
|
+
# render action: "overthere" # won't be called if monkeys is nil
|
205
|
+
# end
|
168
206
|
#
|
169
207
|
class Base < Metal
|
170
208
|
abstract!
|
@@ -172,15 +210,15 @@ module ActionController
|
|
172
210
|
# Shortcut helper that returns all the modules included in
|
173
211
|
# ActionController::Base except the ones passed as arguments:
|
174
212
|
#
|
175
|
-
#
|
176
|
-
#
|
177
|
-
#
|
213
|
+
# class MyBaseController < ActionController::Metal
|
214
|
+
# ActionController::Base.without_modules(:ParamsWrapper, :Streaming).each do |left|
|
215
|
+
# include left
|
216
|
+
# end
|
178
217
|
# end
|
179
|
-
# end
|
180
218
|
#
|
181
|
-
# This gives better control over what you want to exclude and makes it
|
182
|
-
#
|
183
|
-
#
|
219
|
+
# This gives better control over what you want to exclude and makes it easier to
|
220
|
+
# create a bare controller class, instead of listing the modules required
|
221
|
+
# manually.
|
184
222
|
def self.without_modules(*modules)
|
185
223
|
modules = modules.map do |m|
|
186
224
|
m.is_a?(Symbol) ? ActionController.const_get(m) : m
|
@@ -193,7 +231,6 @@ module ActionController
|
|
193
231
|
AbstractController::Rendering,
|
194
232
|
AbstractController::Translation,
|
195
233
|
AbstractController::AssetPaths,
|
196
|
-
|
197
234
|
Helpers,
|
198
235
|
UrlFor,
|
199
236
|
Redirecting,
|
@@ -214,6 +251,8 @@ module ActionController
|
|
214
251
|
RequestForgeryProtection,
|
215
252
|
ContentSecurityPolicy,
|
216
253
|
PermissionsPolicy,
|
254
|
+
RateLimiting,
|
255
|
+
AllowBrowser,
|
217
256
|
Streaming,
|
218
257
|
DataStreaming,
|
219
258
|
HttpAuthentication::Basic::ControllerMethods,
|
@@ -221,32 +260,65 @@ module ActionController
|
|
221
260
|
HttpAuthentication::Token::ControllerMethods,
|
222
261
|
DefaultHeaders,
|
223
262
|
Logging,
|
224
|
-
|
225
|
-
# Before callbacks should also be executed as early as possible, so
|
226
|
-
# also include them at the bottom.
|
227
263
|
AbstractController::Callbacks,
|
228
|
-
|
229
|
-
# Append rescue at the bottom to wrap as much as possible.
|
230
264
|
Rescue,
|
231
|
-
|
232
|
-
# Add instrumentations hooks at the bottom, to ensure they instrument
|
233
|
-
# all the methods properly.
|
234
265
|
Instrumentation,
|
235
|
-
|
236
|
-
# Params wrapper should come before instrumentation so they are
|
237
|
-
# properly showed in logs
|
238
266
|
ParamsWrapper
|
239
267
|
]
|
240
268
|
|
241
|
-
|
242
|
-
|
243
|
-
|
269
|
+
# Note: Documenting these severely degrates the performance of rdoc
|
270
|
+
# :stopdoc:
|
271
|
+
include AbstractController::Rendering
|
272
|
+
include AbstractController::Translation
|
273
|
+
include AbstractController::AssetPaths
|
274
|
+
include Helpers
|
275
|
+
include UrlFor
|
276
|
+
include Redirecting
|
277
|
+
include ActionView::Layouts
|
278
|
+
include Rendering
|
279
|
+
include Renderers::All
|
280
|
+
include ConditionalGet
|
281
|
+
include EtagWithTemplateDigest
|
282
|
+
include EtagWithFlash
|
283
|
+
include Caching
|
284
|
+
include MimeResponds
|
285
|
+
include ImplicitRender
|
286
|
+
include StrongParameters
|
287
|
+
include ParameterEncoding
|
288
|
+
include Cookies
|
289
|
+
include Flash
|
290
|
+
include FormBuilder
|
291
|
+
include RequestForgeryProtection
|
292
|
+
include ContentSecurityPolicy
|
293
|
+
include PermissionsPolicy
|
294
|
+
include RateLimiting
|
295
|
+
include AllowBrowser
|
296
|
+
include Streaming
|
297
|
+
include DataStreaming
|
298
|
+
include HttpAuthentication::Basic::ControllerMethods
|
299
|
+
include HttpAuthentication::Digest::ControllerMethods
|
300
|
+
include HttpAuthentication::Token::ControllerMethods
|
301
|
+
include DefaultHeaders
|
302
|
+
include Logging
|
303
|
+
# Before callbacks should also be executed as early as possible, so also include
|
304
|
+
# them at the bottom.
|
305
|
+
include AbstractController::Callbacks
|
306
|
+
# Append rescue at the bottom to wrap as much as possible.
|
307
|
+
include Rescue
|
308
|
+
# Add instrumentations hooks at the bottom, to ensure they instrument all the
|
309
|
+
# methods properly.
|
310
|
+
include Instrumentation
|
311
|
+
# Params wrapper should come before instrumentation so they are properly showed
|
312
|
+
# in logs
|
313
|
+
include ParamsWrapper
|
314
|
+
# :startdoc:
|
244
315
|
setup_renderer!
|
245
316
|
|
246
317
|
# Define some internal variables that should not be propagated to the view.
|
247
318
|
PROTECTED_IVARS = AbstractController::Rendering::DEFAULT_PROTECTED_INSTANCE_VARIABLES + %i(
|
248
319
|
@_params @_response @_request @_config @_url_options @_action_has_layout @_view_context_class
|
249
320
|
@_view_renderer @_lookup_context @_routes @_view_runtime @_db_runtime @_helper_proxy
|
321
|
+
@_marked_for_same_origin_verification @_rendered_format
|
250
322
|
)
|
251
323
|
|
252
324
|
def _protected_ivars
|
@@ -1,28 +1,31 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# :markup: markdown
|
4
|
+
|
3
5
|
module ActionController
|
4
|
-
#
|
6
|
+
# # Action Controller Caching
|
5
7
|
#
|
6
|
-
#
|
7
|
-
# calculations, renderings, and database calls around for subsequent
|
8
|
+
# Caching is a cheap way of speeding up slow applications by keeping the result
|
9
|
+
# of calculations, renderings, and database calls around for subsequent
|
10
|
+
# requests.
|
8
11
|
#
|
9
12
|
# You can read more about each approach by clicking the modules below.
|
10
13
|
#
|
11
14
|
# Note: To turn off all caching provided by Action Controller, set
|
12
|
-
#
|
15
|
+
# config.action_controller.perform_caching = false
|
13
16
|
#
|
14
|
-
#
|
17
|
+
# ## Caching stores
|
15
18
|
#
|
16
|
-
# All the caching stores from ActiveSupport::Cache are available to be used as
|
17
|
-
# for Action Controller caching.
|
19
|
+
# All the caching stores from ActiveSupport::Cache are available to be used as
|
20
|
+
# backends for Action Controller caching.
|
18
21
|
#
|
19
22
|
# Configuration examples (FileStore is the default):
|
20
23
|
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
24
|
+
# config.action_controller.cache_store = :memory_store
|
25
|
+
# config.action_controller.cache_store = :file_store, '/path/to/cache/directory'
|
26
|
+
# config.action_controller.cache_store = :mem_cache_store, 'localhost'
|
27
|
+
# config.action_controller.cache_store = :mem_cache_store, Memcached::Rails.new('localhost:11211')
|
28
|
+
# config.action_controller.cache_store = MyOwnStore.new('parameter')
|
26
29
|
module Caching
|
27
30
|
extend ActiveSupport::Concern
|
28
31
|
|
@@ -1,31 +1,33 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# :markup: markdown
|
4
|
+
|
3
5
|
module ActionController
|
4
|
-
#
|
6
|
+
# # Action Controller Form Builder
|
5
7
|
#
|
6
|
-
# Override the default form builder for all views rendered by this
|
7
|
-
#
|
8
|
+
# Override the default form builder for all views rendered by this controller
|
9
|
+
# and any of its descendants. Accepts a subclass of
|
8
10
|
# ActionView::Helpers::FormBuilder.
|
9
11
|
#
|
10
12
|
# For example, given a form builder:
|
11
13
|
#
|
12
|
-
#
|
13
|
-
#
|
14
|
+
# class AdminFormBuilder < ActionView::Helpers::FormBuilder
|
15
|
+
# def special_field(name)
|
16
|
+
# end
|
14
17
|
# end
|
15
|
-
# end
|
16
18
|
#
|
17
19
|
# The controller specifies a form builder as its default:
|
18
20
|
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
21
|
+
# class AdminAreaController < ApplicationController
|
22
|
+
# default_form_builder AdminFormBuilder
|
23
|
+
# end
|
22
24
|
#
|
23
|
-
# Then in the view any form using
|
25
|
+
# Then in the view any form using `form_for` will be an instance of the
|
24
26
|
# specified form builder:
|
25
27
|
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
28
|
+
# <%= form_for(@instance) do |builder| %>
|
29
|
+
# <%= builder.special_field(:name) %>
|
30
|
+
# <% end %>
|
29
31
|
module FormBuilder
|
30
32
|
extend ActiveSupport::Concern
|
31
33
|
|
@@ -34,11 +36,12 @@ module ActionController
|
|
34
36
|
end
|
35
37
|
|
36
38
|
module ClassMethods
|
37
|
-
# Set the form builder to be used as the default for all forms
|
38
|
-
#
|
39
|
+
# Set the form builder to be used as the default for all forms in the views
|
40
|
+
# rendered by this controller and its subclasses.
|
39
41
|
#
|
40
|
-
#
|
41
|
-
# *
|
42
|
+
# #### Parameters
|
43
|
+
# * `builder` - Default form builder, an instance of
|
44
|
+
# ActionView::Helpers::FormBuilder
|
42
45
|
def default_form_builder(builder)
|
43
46
|
self._default_form_builder = builder
|
44
47
|
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# :markup: markdown
|
4
|
+
|
3
5
|
module ActionController
|
4
6
|
class LogSubscriber < ActiveSupport::LogSubscriber
|
5
7
|
INTERNAL_PARAMS = %w(controller action format _method only_path)
|
@@ -31,7 +33,7 @@ module ActionController
|
|
31
33
|
status = ActionDispatch::ExceptionWrapper.status_code_for_exception(exception_class_name)
|
32
34
|
end
|
33
35
|
|
34
|
-
additions << "
|
36
|
+
additions << "GC: #{event.gc_time.round(1)}ms"
|
35
37
|
|
36
38
|
message = +"Completed #{status} #{Rack::Utils::HTTP_STATUS_CODES[status]} in #{event.duration.round}ms" \
|
37
39
|
" (#{additions.join(" | ")})"
|