actionpack 4.2.8 → 5.2.4.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of actionpack might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/CHANGELOG.md +285 -444
- data/MIT-LICENSE +1 -1
- data/README.rdoc +6 -7
- data/lib/abstract_controller.rb +12 -5
- data/lib/abstract_controller/asset_paths.rb +2 -0
- data/lib/abstract_controller/base.rb +45 -49
- data/lib/abstract_controller/caching.rb +66 -0
- data/lib/{action_controller → abstract_controller}/caching/fragments.rb +78 -15
- data/lib/abstract_controller/callbacks.rb +47 -31
- data/lib/abstract_controller/collector.rb +8 -11
- data/lib/abstract_controller/error.rb +6 -0
- data/lib/abstract_controller/helpers.rb +25 -25
- data/lib/abstract_controller/logger.rb +2 -0
- data/lib/abstract_controller/railties/routes_helpers.rb +4 -2
- data/lib/abstract_controller/rendering.rb +42 -41
- data/lib/abstract_controller/translation.rb +10 -7
- data/lib/abstract_controller/url_for.rb +2 -0
- data/lib/action_controller.rb +29 -21
- data/lib/action_controller/api.rb +149 -0
- data/lib/action_controller/api/api_rendering.rb +16 -0
- data/lib/action_controller/base.rb +27 -19
- data/lib/action_controller/caching.rb +14 -57
- data/lib/action_controller/form_builder.rb +50 -0
- data/lib/action_controller/log_subscriber.rb +10 -15
- data/lib/action_controller/metal.rb +98 -83
- data/lib/action_controller/metal/basic_implicit_render.rb +13 -0
- data/lib/action_controller/metal/conditional_get.rb +118 -44
- data/lib/action_controller/metal/content_security_policy.rb +52 -0
- data/lib/action_controller/metal/cookies.rb +3 -3
- data/lib/action_controller/metal/data_streaming.rb +27 -46
- data/lib/action_controller/metal/etag_with_flash.rb +18 -0
- data/lib/action_controller/metal/etag_with_template_digest.rb +20 -13
- data/lib/action_controller/metal/exceptions.rb +8 -14
- data/lib/action_controller/metal/flash.rb +4 -3
- data/lib/action_controller/metal/force_ssl.rb +23 -21
- data/lib/action_controller/metal/head.rb +21 -19
- data/lib/action_controller/metal/helpers.rb +24 -14
- data/lib/action_controller/metal/http_authentication.rb +64 -57
- data/lib/action_controller/metal/implicit_render.rb +62 -8
- data/lib/action_controller/metal/instrumentation.rb +19 -21
- data/lib/action_controller/metal/live.rb +90 -106
- data/lib/action_controller/metal/mime_responds.rb +33 -46
- data/lib/action_controller/metal/parameter_encoding.rb +51 -0
- data/lib/action_controller/metal/params_wrapper.rb +61 -53
- data/lib/action_controller/metal/redirecting.rb +49 -28
- data/lib/action_controller/metal/renderers.rb +87 -44
- data/lib/action_controller/metal/rendering.rb +72 -50
- data/lib/action_controller/metal/request_forgery_protection.rb +203 -92
- data/lib/action_controller/metal/rescue.rb +9 -16
- data/lib/action_controller/metal/streaming.rb +12 -10
- data/lib/action_controller/metal/strong_parameters.rb +582 -165
- data/lib/action_controller/metal/testing.rb +2 -17
- data/lib/action_controller/metal/url_for.rb +19 -10
- data/lib/action_controller/railtie.rb +28 -10
- data/lib/action_controller/railties/helpers.rb +2 -0
- data/lib/action_controller/renderer.rb +117 -0
- data/lib/action_controller/template_assertions.rb +11 -0
- data/lib/action_controller/test_case.rb +280 -411
- data/lib/action_dispatch.rb +27 -19
- data/lib/action_dispatch/http/cache.rb +93 -47
- data/lib/action_dispatch/http/content_security_policy.rb +272 -0
- data/lib/action_dispatch/http/filter_parameters.rb +26 -20
- data/lib/action_dispatch/http/filter_redirect.rb +10 -11
- data/lib/action_dispatch/http/headers.rb +55 -22
- data/lib/action_dispatch/http/mime_negotiation.rb +60 -41
- data/lib/action_dispatch/http/mime_type.rb +134 -121
- data/lib/action_dispatch/http/mime_types.rb +20 -6
- data/lib/action_dispatch/http/parameter_filter.rb +25 -11
- data/lib/action_dispatch/http/parameters.rb +98 -39
- data/lib/action_dispatch/http/rack_cache.rb +2 -0
- data/lib/action_dispatch/http/request.rb +200 -118
- data/lib/action_dispatch/http/response.rb +225 -110
- data/lib/action_dispatch/http/upload.rb +12 -6
- data/lib/action_dispatch/http/url.rb +110 -28
- data/lib/action_dispatch/journey.rb +7 -5
- data/lib/action_dispatch/journey/formatter.rb +55 -32
- data/lib/action_dispatch/journey/gtg/builder.rb +7 -5
- data/lib/action_dispatch/journey/gtg/simulator.rb +3 -9
- data/lib/action_dispatch/journey/gtg/transition_table.rb +17 -16
- data/lib/action_dispatch/journey/nfa/builder.rb +5 -3
- data/lib/action_dispatch/journey/nfa/dot.rb +13 -13
- data/lib/action_dispatch/journey/nfa/simulator.rb +3 -1
- data/lib/action_dispatch/journey/nfa/transition_table.rb +5 -48
- data/lib/action_dispatch/journey/nodes/node.rb +18 -6
- data/lib/action_dispatch/journey/parser.rb +23 -22
- data/lib/action_dispatch/journey/parser.y +3 -2
- data/lib/action_dispatch/journey/parser_extras.rb +12 -4
- data/lib/action_dispatch/journey/path/pattern.rb +50 -44
- data/lib/action_dispatch/journey/route.rb +106 -28
- data/lib/action_dispatch/journey/router.rb +35 -23
- data/lib/action_dispatch/journey/router/utils.rb +20 -11
- data/lib/action_dispatch/journey/routes.rb +18 -16
- data/lib/action_dispatch/journey/scanner.rb +18 -15
- data/lib/action_dispatch/journey/visitors.rb +99 -52
- data/lib/action_dispatch/middleware/callbacks.rb +1 -2
- data/lib/action_dispatch/middleware/cookies.rb +304 -193
- data/lib/action_dispatch/middleware/debug_exceptions.rb +152 -57
- data/lib/action_dispatch/middleware/debug_locks.rb +124 -0
- data/lib/action_dispatch/middleware/exception_wrapper.rb +68 -69
- data/lib/action_dispatch/middleware/executor.rb +21 -0
- data/lib/action_dispatch/middleware/flash.rb +78 -54
- data/lib/action_dispatch/middleware/public_exceptions.rb +27 -25
- data/lib/action_dispatch/middleware/reloader.rb +5 -91
- data/lib/action_dispatch/middleware/remote_ip.rb +41 -31
- data/lib/action_dispatch/middleware/request_id.rb +17 -9
- data/lib/action_dispatch/middleware/session/abstract_store.rb +41 -25
- data/lib/action_dispatch/middleware/session/cache_store.rb +24 -14
- data/lib/action_dispatch/middleware/session/cookie_store.rb +72 -67
- data/lib/action_dispatch/middleware/session/mem_cache_store.rb +8 -2
- data/lib/action_dispatch/middleware/show_exceptions.rb +26 -22
- data/lib/action_dispatch/middleware/ssl.rb +114 -36
- data/lib/action_dispatch/middleware/stack.rb +31 -44
- data/lib/action_dispatch/middleware/static.rb +57 -50
- data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb +2 -14
- data/lib/action_dispatch/middleware/templates/rescues/{_source.erb → _source.html.erb} +0 -0
- data/lib/action_dispatch/middleware/templates/rescues/_source.text.erb +8 -0
- data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.html.erb +21 -0
- data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.text.erb +13 -0
- data/lib/action_dispatch/middleware/templates/rescues/layout.erb +1 -0
- data/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb +1 -1
- data/lib/action_dispatch/middleware/templates/rescues/template_error.text.erb +1 -1
- data/lib/action_dispatch/middleware/templates/routes/_route.html.erb +4 -4
- data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +64 -64
- data/lib/action_dispatch/railtie.rb +19 -11
- data/lib/action_dispatch/request/session.rb +106 -59
- data/lib/action_dispatch/request/utils.rb +67 -24
- data/lib/action_dispatch/routing.rb +17 -18
- data/lib/action_dispatch/routing/endpoint.rb +9 -2
- data/lib/action_dispatch/routing/inspector.rb +58 -67
- data/lib/action_dispatch/routing/mapper.rb +734 -447
- data/lib/action_dispatch/routing/polymorphic_routes.rb +161 -139
- data/lib/action_dispatch/routing/redirection.rb +36 -26
- data/lib/action_dispatch/routing/route_set.rb +321 -291
- data/lib/action_dispatch/routing/routes_proxy.rb +32 -5
- data/lib/action_dispatch/routing/url_for.rb +65 -25
- data/lib/action_dispatch/system_test_case.rb +147 -0
- data/lib/action_dispatch/system_testing/browser.rb +49 -0
- data/lib/action_dispatch/system_testing/driver.rb +59 -0
- data/lib/action_dispatch/system_testing/server.rb +31 -0
- data/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb +96 -0
- data/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb +31 -0
- data/lib/action_dispatch/system_testing/test_helpers/undef_methods.rb +26 -0
- data/lib/action_dispatch/testing/assertion_response.rb +47 -0
- data/lib/action_dispatch/testing/assertions.rb +6 -4
- data/lib/action_dispatch/testing/assertions/response.rb +45 -20
- data/lib/action_dispatch/testing/assertions/routing.rb +30 -26
- data/lib/action_dispatch/testing/integration.rb +347 -209
- data/lib/action_dispatch/testing/request_encoder.rb +55 -0
- data/lib/action_dispatch/testing/test_process.rb +28 -22
- data/lib/action_dispatch/testing/test_request.rb +27 -34
- data/lib/action_dispatch/testing/test_response.rb +35 -7
- data/lib/action_pack.rb +4 -2
- data/lib/action_pack/gem_version.rb +5 -3
- data/lib/action_pack/version.rb +3 -1
- metadata +56 -39
- data/lib/action_controller/metal/hide_actions.rb +0 -40
- data/lib/action_controller/metal/rack_delegation.rb +0 -32
- data/lib/action_controller/middleware.rb +0 -39
- data/lib/action_controller/model_naming.rb +0 -12
- data/lib/action_dispatch/journey/backwards.rb +0 -5
- data/lib/action_dispatch/journey/router/strexp.rb +0 -27
- data/lib/action_dispatch/middleware/params_parser.rb +0 -60
- data/lib/action_dispatch/testing/assertions/dom.rb +0 -3
- data/lib/action_dispatch/testing/assertions/selector.rb +0 -3
- data/lib/action_dispatch/testing/assertions/tag.rb +0 -3
data/lib/action_controller.rb
CHANGED
@@ -1,34 +1,42 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/rails"
|
4
|
+
require "abstract_controller"
|
5
|
+
require "action_dispatch"
|
6
|
+
require "action_controller/metal/live"
|
7
|
+
require "action_controller/metal/strong_parameters"
|
6
8
|
|
7
9
|
module ActionController
|
8
10
|
extend ActiveSupport::Autoload
|
9
11
|
|
12
|
+
autoload :API
|
10
13
|
autoload :Base
|
11
|
-
autoload :Caching
|
12
14
|
autoload :Metal
|
13
15
|
autoload :Middleware
|
16
|
+
autoload :Renderer
|
17
|
+
autoload :FormBuilder
|
18
|
+
|
19
|
+
eager_autoload do
|
20
|
+
autoload :Caching
|
21
|
+
end
|
14
22
|
|
15
23
|
autoload_under "metal" do
|
16
|
-
autoload :Compatibility
|
17
24
|
autoload :ConditionalGet
|
25
|
+
autoload :ContentSecurityPolicy
|
18
26
|
autoload :Cookies
|
19
27
|
autoload :DataStreaming
|
20
28
|
autoload :EtagWithTemplateDigest
|
29
|
+
autoload :EtagWithFlash
|
21
30
|
autoload :Flash
|
22
31
|
autoload :ForceSSL
|
23
32
|
autoload :Head
|
24
33
|
autoload :Helpers
|
25
|
-
autoload :HideActions
|
26
34
|
autoload :HttpAuthentication
|
35
|
+
autoload :BasicImplicitRender
|
27
36
|
autoload :ImplicitRender
|
28
37
|
autoload :Instrumentation
|
29
38
|
autoload :MimeResponds
|
30
39
|
autoload :ParamsWrapper
|
31
|
-
autoload :RackDelegation
|
32
40
|
autoload :Redirecting
|
33
41
|
autoload :Renderers
|
34
42
|
autoload :Rendering
|
@@ -36,23 +44,23 @@ module ActionController
|
|
36
44
|
autoload :Rescue
|
37
45
|
autoload :Streaming
|
38
46
|
autoload :StrongParameters
|
47
|
+
autoload :ParameterEncoding
|
39
48
|
autoload :Testing
|
40
49
|
autoload :UrlFor
|
41
50
|
end
|
42
51
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
def self.eager_load!
|
47
|
-
super
|
48
|
-
ActionController::Caching.eager_load!
|
52
|
+
autoload_under "api" do
|
53
|
+
autoload :ApiRendering
|
49
54
|
end
|
55
|
+
|
56
|
+
autoload :TestCase, "action_controller/test_case"
|
57
|
+
autoload :TemplateAssertions, "action_controller/test_case"
|
50
58
|
end
|
51
59
|
|
52
60
|
# Common Active Support usage in Action Controller
|
53
|
-
require
|
54
|
-
require
|
55
|
-
require
|
56
|
-
require
|
57
|
-
require
|
58
|
-
require
|
61
|
+
require "active_support/core_ext/module/attribute_accessors"
|
62
|
+
require "active_support/core_ext/load_error"
|
63
|
+
require "active_support/core_ext/module/attr_internal"
|
64
|
+
require "active_support/core_ext/name_error"
|
65
|
+
require "active_support/core_ext/uri"
|
66
|
+
require "active_support/inflector"
|
@@ -0,0 +1,149 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "action_view"
|
4
|
+
require "action_controller"
|
5
|
+
require "action_controller/log_subscriber"
|
6
|
+
|
7
|
+
module ActionController
|
8
|
+
# API Controller is a lightweight version of <tt>ActionController::Base</tt>,
|
9
|
+
# created for applications that don't require all functionalities that a complete
|
10
|
+
# \Rails controller provides, allowing you to create controllers with just the
|
11
|
+
# features that you need for API only applications.
|
12
|
+
#
|
13
|
+
# An API Controller is different from a normal controller in the sense that
|
14
|
+
# by default it doesn't include a number of features that are usually required
|
15
|
+
# by browser access only: layouts and templates rendering, cookies, sessions,
|
16
|
+
# flash, assets, and so on. This makes the entire controller stack thinner,
|
17
|
+
# suitable for API applications. It doesn't mean you won't have such
|
18
|
+
# features if you need them: they're all available for you to include in
|
19
|
+
# your application, they're just not part of the default API controller stack.
|
20
|
+
#
|
21
|
+
# Normally, +ApplicationController+ is the only controller that inherits from
|
22
|
+
# <tt>ActionController::API</tt>. All other controllers in turn inherit from
|
23
|
+
# +ApplicationController+.
|
24
|
+
#
|
25
|
+
# A sample controller could look like this:
|
26
|
+
#
|
27
|
+
# class PostsController < ApplicationController
|
28
|
+
# def index
|
29
|
+
# posts = Post.all
|
30
|
+
# render json: posts
|
31
|
+
# end
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
# Request, response, and parameters objects all work the exact same way as
|
35
|
+
# <tt>ActionController::Base</tt>.
|
36
|
+
#
|
37
|
+
# == Renders
|
38
|
+
#
|
39
|
+
# The default API Controller stack includes all renderers, which means you
|
40
|
+
# can use <tt>render :json</tt> and brothers freely in your controllers. Keep
|
41
|
+
# in mind that templates are not going to be rendered, so you need to ensure
|
42
|
+
# your controller is calling either <tt>render</tt> or <tt>redirect_to</tt> in
|
43
|
+
# all actions, otherwise it will return 204 No Content.
|
44
|
+
#
|
45
|
+
# def show
|
46
|
+
# post = Post.find(params[:id])
|
47
|
+
# render json: post
|
48
|
+
# end
|
49
|
+
#
|
50
|
+
# == Redirects
|
51
|
+
#
|
52
|
+
# Redirects are used to move from one action to another. You can use the
|
53
|
+
# <tt>redirect_to</tt> method in your controllers in the same way as in
|
54
|
+
# <tt>ActionController::Base</tt>. For example:
|
55
|
+
#
|
56
|
+
# def create
|
57
|
+
# redirect_to root_url and return if not_authorized?
|
58
|
+
# # do stuff here
|
59
|
+
# end
|
60
|
+
#
|
61
|
+
# == Adding New Behavior
|
62
|
+
#
|
63
|
+
# In some scenarios you may want to add back some functionality provided by
|
64
|
+
# <tt>ActionController::Base</tt> that is not present by default in
|
65
|
+
# <tt>ActionController::API</tt>, for instance <tt>MimeResponds</tt>. This
|
66
|
+
# module gives you the <tt>respond_to</tt> method. Adding it is quite simple,
|
67
|
+
# you just need to include the module in a specific controller or in
|
68
|
+
# +ApplicationController+ in case you want it available in your entire
|
69
|
+
# application:
|
70
|
+
#
|
71
|
+
# class ApplicationController < ActionController::API
|
72
|
+
# include ActionController::MimeResponds
|
73
|
+
# end
|
74
|
+
#
|
75
|
+
# class PostsController < ApplicationController
|
76
|
+
# def index
|
77
|
+
# posts = Post.all
|
78
|
+
#
|
79
|
+
# respond_to do |format|
|
80
|
+
# format.json { render json: posts }
|
81
|
+
# format.xml { render xml: posts }
|
82
|
+
# end
|
83
|
+
# end
|
84
|
+
# end
|
85
|
+
#
|
86
|
+
# Make sure to check the modules included in <tt>ActionController::Base</tt>
|
87
|
+
# if you want to use any other functionality that is not provided
|
88
|
+
# by <tt>ActionController::API</tt> out of the box.
|
89
|
+
class API < Metal
|
90
|
+
abstract!
|
91
|
+
|
92
|
+
# Shortcut helper that returns all the ActionController::API modules except
|
93
|
+
# the ones passed as arguments:
|
94
|
+
#
|
95
|
+
# class MyAPIBaseController < ActionController::Metal
|
96
|
+
# ActionController::API.without_modules(:ForceSSL, :UrlFor).each do |left|
|
97
|
+
# include left
|
98
|
+
# end
|
99
|
+
# end
|
100
|
+
#
|
101
|
+
# This gives better control over what you want to exclude and makes it easier
|
102
|
+
# to create an API controller class, instead of listing the modules required
|
103
|
+
# manually.
|
104
|
+
def self.without_modules(*modules)
|
105
|
+
modules = modules.map do |m|
|
106
|
+
m.is_a?(Symbol) ? ActionController.const_get(m) : m
|
107
|
+
end
|
108
|
+
|
109
|
+
MODULES - modules
|
110
|
+
end
|
111
|
+
|
112
|
+
MODULES = [
|
113
|
+
AbstractController::Rendering,
|
114
|
+
|
115
|
+
UrlFor,
|
116
|
+
Redirecting,
|
117
|
+
ApiRendering,
|
118
|
+
Renderers::All,
|
119
|
+
ConditionalGet,
|
120
|
+
BasicImplicitRender,
|
121
|
+
StrongParameters,
|
122
|
+
|
123
|
+
ForceSSL,
|
124
|
+
DataStreaming,
|
125
|
+
|
126
|
+
# Before callbacks should also be executed as early as possible, so
|
127
|
+
# also include them at the bottom.
|
128
|
+
AbstractController::Callbacks,
|
129
|
+
|
130
|
+
# Append rescue at the bottom to wrap as much as possible.
|
131
|
+
Rescue,
|
132
|
+
|
133
|
+
# Add instrumentations hooks at the bottom, to ensure they instrument
|
134
|
+
# all the methods properly.
|
135
|
+
Instrumentation,
|
136
|
+
|
137
|
+
# Params wrapper should come before instrumentation so they are
|
138
|
+
# properly showed in logs
|
139
|
+
ParamsWrapper
|
140
|
+
]
|
141
|
+
|
142
|
+
MODULES.each do |mod|
|
143
|
+
include mod
|
144
|
+
end
|
145
|
+
|
146
|
+
ActiveSupport.run_load_hooks(:action_controller_api, self)
|
147
|
+
ActiveSupport.run_load_hooks(:action_controller, self)
|
148
|
+
end
|
149
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActionController
|
4
|
+
module ApiRendering
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
include Rendering
|
9
|
+
end
|
10
|
+
|
11
|
+
def render_to_body(options = {})
|
12
|
+
_process_options(options)
|
13
|
+
super
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "action_view"
|
2
4
|
require "action_controller/log_subscriber"
|
3
5
|
require "action_controller/metal/params_wrapper"
|
4
6
|
|
@@ -8,7 +10,7 @@ module ActionController
|
|
8
10
|
# on the controller, which will automatically be made accessible to the web-server through \Rails Routes.
|
9
11
|
#
|
10
12
|
# By default, only the ApplicationController in a \Rails application inherits from <tt>ActionController::Base</tt>. All other
|
11
|
-
# controllers
|
13
|
+
# controllers inherit from ApplicationController. This gives you one class to configure things such as
|
12
14
|
# request forgery protection and filtering of sensitive request parameters.
|
13
15
|
#
|
14
16
|
# A sample controller could look like this:
|
@@ -30,9 +32,9 @@ module ActionController
|
|
30
32
|
#
|
31
33
|
# Unlike index, the create action will not render a template. After performing its main purpose (creating a
|
32
34
|
# new post), it initiates a redirect instead. This redirect works by returning an external
|
33
|
-
#
|
35
|
+
# <tt>302 Moved</tt> HTTP response that takes the user to the index action.
|
34
36
|
#
|
35
|
-
# These two methods represent the two basic action archetypes used in Action Controllers
|
37
|
+
# These two methods represent the two basic action archetypes used in Action Controllers: Get-and-show and do-and-redirect.
|
36
38
|
# Most actions are variations on these themes.
|
37
39
|
#
|
38
40
|
# == Requests
|
@@ -50,17 +52,17 @@ module ActionController
|
|
50
52
|
#
|
51
53
|
# == Parameters
|
52
54
|
#
|
53
|
-
# All request parameters, whether they come from a
|
54
|
-
# which returns a hash. For example, an action that was performed through
|
55
|
-
# <tt>{ "category" => "All", "limit" => "5" }</tt> in params
|
55
|
+
# All request parameters, whether they come from a query string in the URL or form data submitted through a POST request are
|
56
|
+
# available through the <tt>params</tt> method which returns a hash. For example, an action that was performed through
|
57
|
+
# <tt>/posts?category=All&limit=5</tt> will include <tt>{ "category" => "All", "limit" => "5" }</tt> in <tt>params</tt>.
|
56
58
|
#
|
57
59
|
# It's also possible to construct multi-dimensional parameter hashes by specifying keys using brackets, such as:
|
58
60
|
#
|
59
61
|
# <input type="text" name="post[name]" value="david">
|
60
62
|
# <input type="text" name="post[address]" value="hyacintvej">
|
61
63
|
#
|
62
|
-
# A request
|
63
|
-
# If the address input had been named <tt>post[address][street]</tt>, the params would have included
|
64
|
+
# A request coming from a form holding these inputs will include <tt>{ "post" => { "name" => "david", "address" => "hyacintvej" } }</tt>.
|
65
|
+
# If the address input had been named <tt>post[address][street]</tt>, the <tt>params</tt> would have included
|
64
66
|
# <tt>{ "post" => { "address" => { "street" => "hyacintvej" } } }</tt>. There's no limit to the depth of the nesting.
|
65
67
|
#
|
66
68
|
# == Sessions
|
@@ -74,7 +76,7 @@ module ActionController
|
|
74
76
|
#
|
75
77
|
# session[:person] = Person.authenticate(user_name, password)
|
76
78
|
#
|
77
|
-
#
|
79
|
+
# You can retrieve it again through the same hash:
|
78
80
|
#
|
79
81
|
# Hello #{session[:person]}
|
80
82
|
#
|
@@ -206,7 +208,6 @@ module ActionController
|
|
206
208
|
AbstractController::AssetPaths,
|
207
209
|
|
208
210
|
Helpers,
|
209
|
-
HideActions,
|
210
211
|
UrlFor,
|
211
212
|
Redirecting,
|
212
213
|
ActionView::Layouts,
|
@@ -214,15 +215,17 @@ module ActionController
|
|
214
215
|
Renderers::All,
|
215
216
|
ConditionalGet,
|
216
217
|
EtagWithTemplateDigest,
|
217
|
-
|
218
|
+
EtagWithFlash,
|
218
219
|
Caching,
|
219
220
|
MimeResponds,
|
220
221
|
ImplicitRender,
|
221
222
|
StrongParameters,
|
222
|
-
|
223
|
+
ParameterEncoding,
|
223
224
|
Cookies,
|
224
225
|
Flash,
|
226
|
+
FormBuilder,
|
225
227
|
RequestForgeryProtection,
|
228
|
+
ContentSecurityPolicy,
|
226
229
|
ForceSSL,
|
227
230
|
Streaming,
|
228
231
|
DataStreaming,
|
@@ -230,7 +233,7 @@ module ActionController
|
|
230
233
|
HttpAuthentication::Digest::ControllerMethods,
|
231
234
|
HttpAuthentication::Token::ControllerMethods,
|
232
235
|
|
233
|
-
# Before callbacks should also be executed
|
236
|
+
# Before callbacks should also be executed as early as possible, so
|
234
237
|
# also include them at the bottom.
|
235
238
|
AbstractController::Callbacks,
|
236
239
|
|
@@ -249,20 +252,25 @@ module ActionController
|
|
249
252
|
MODULES.each do |mod|
|
250
253
|
include mod
|
251
254
|
end
|
255
|
+
setup_renderer!
|
252
256
|
|
253
257
|
# Define some internal variables that should not be propagated to the view.
|
254
|
-
PROTECTED_IVARS = AbstractController::Rendering::DEFAULT_PROTECTED_INSTANCE_VARIABLES +
|
255
|
-
|
256
|
-
|
258
|
+
PROTECTED_IVARS = AbstractController::Rendering::DEFAULT_PROTECTED_INSTANCE_VARIABLES + %i(
|
259
|
+
@_params @_response @_request @_config @_url_options @_action_has_layout @_view_context_class
|
260
|
+
@_view_renderer @_lookup_context @_routes @_view_runtime @_db_runtime @_helper_proxy
|
261
|
+
)
|
257
262
|
|
258
263
|
def _protected_ivars # :nodoc:
|
259
264
|
PROTECTED_IVARS
|
260
265
|
end
|
261
266
|
|
262
|
-
def self.
|
263
|
-
|
267
|
+
def self.make_response!(request)
|
268
|
+
ActionDispatch::Response.create.tap do |res|
|
269
|
+
res.request = request
|
270
|
+
end
|
264
271
|
end
|
265
272
|
|
273
|
+
ActiveSupport.run_load_hooks(:action_controller_base, self)
|
266
274
|
ActiveSupport.run_load_hooks(:action_controller, self)
|
267
275
|
end
|
268
276
|
end
|
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
require 'uri'
|
3
|
-
require 'set'
|
1
|
+
# frozen_string_literal: true
|
4
2
|
|
5
3
|
module ActionController
|
6
4
|
# \Caching is a cheap way of speeding up slow applications by keeping the result of
|
@@ -8,7 +6,7 @@ module ActionController
|
|
8
6
|
#
|
9
7
|
# You can read more about each approach by clicking the modules below.
|
10
8
|
#
|
11
|
-
# Note: To turn off all caching, set
|
9
|
+
# Note: To turn off all caching provided by Action Controller, set
|
12
10
|
# config.action_controller.perform_caching = false
|
13
11
|
#
|
14
12
|
# == \Caching stores
|
@@ -24,66 +22,25 @@ module ActionController
|
|
24
22
|
# config.action_controller.cache_store = :mem_cache_store, Memcached::Rails.new('localhost:11211')
|
25
23
|
# config.action_controller.cache_store = MyOwnStore.new('parameter')
|
26
24
|
module Caching
|
27
|
-
extend ActiveSupport::Concern
|
28
25
|
extend ActiveSupport::Autoload
|
29
|
-
|
30
|
-
eager_autoload do
|
31
|
-
autoload :Fragments
|
32
|
-
end
|
33
|
-
|
34
|
-
module ConfigMethods
|
35
|
-
def cache_store
|
36
|
-
config.cache_store
|
37
|
-
end
|
38
|
-
|
39
|
-
def cache_store=(store)
|
40
|
-
config.cache_store = ActiveSupport::Cache.lookup_store(store)
|
41
|
-
end
|
42
|
-
|
43
|
-
private
|
44
|
-
def cache_configured?
|
45
|
-
perform_caching && cache_store
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
include RackDelegation
|
50
|
-
include AbstractController::Callbacks
|
51
|
-
|
52
|
-
include ConfigMethods
|
53
|
-
include Fragments
|
26
|
+
extend ActiveSupport::Concern
|
54
27
|
|
55
28
|
included do
|
56
|
-
|
57
|
-
|
58
|
-
config_accessor :default_static_extension
|
59
|
-
self.default_static_extension ||= '.html'
|
60
|
-
|
61
|
-
config_accessor :perform_caching
|
62
|
-
self.perform_caching = true if perform_caching.nil?
|
63
|
-
|
64
|
-
class_attribute :_view_cache_dependencies
|
65
|
-
self._view_cache_dependencies = []
|
66
|
-
helper_method :view_cache_dependencies if respond_to?(:helper_method)
|
29
|
+
include AbstractController::Caching
|
67
30
|
end
|
68
31
|
|
69
|
-
|
70
|
-
def view_cache_dependency(&dependency)
|
71
|
-
self._view_cache_dependencies += [dependency]
|
72
|
-
end
|
73
|
-
end
|
32
|
+
private
|
74
33
|
|
75
|
-
|
76
|
-
|
77
|
-
|
34
|
+
def instrument_payload(key)
|
35
|
+
{
|
36
|
+
controller: controller_name,
|
37
|
+
action: action_name,
|
38
|
+
key: key
|
39
|
+
}
|
40
|
+
end
|
78
41
|
|
79
|
-
|
80
|
-
|
81
|
-
def cache(key, options = {}, &block)
|
82
|
-
if cache_configured?
|
83
|
-
cache_store.fetch(ActiveSupport::Cache.expand_cache_key(key, :controller), options, &block)
|
84
|
-
else
|
85
|
-
yield
|
86
|
-
end
|
42
|
+
def instrument_name
|
43
|
+
"action_controller".freeze
|
87
44
|
end
|
88
45
|
end
|
89
46
|
end
|