actionpack 4.2.10 → 7.2.0.rc1

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.

Files changed (202) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +86 -600
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +13 -14
  5. data/lib/abstract_controller/asset_paths.rb +5 -1
  6. data/lib/abstract_controller/base.rb +166 -136
  7. data/lib/abstract_controller/caching/fragments.rb +149 -0
  8. data/lib/abstract_controller/caching.rb +68 -0
  9. data/lib/abstract_controller/callbacks.rb +126 -57
  10. data/lib/abstract_controller/collector.rb +13 -15
  11. data/lib/abstract_controller/deprecator.rb +9 -0
  12. data/lib/abstract_controller/error.rb +8 -0
  13. data/lib/abstract_controller/helpers.rb +181 -132
  14. data/lib/abstract_controller/logger.rb +5 -1
  15. data/lib/abstract_controller/railties/routes_helpers.rb +10 -3
  16. data/lib/abstract_controller/rendering.rb +56 -56
  17. data/lib/abstract_controller/translation.rb +29 -15
  18. data/lib/abstract_controller/url_for.rb +15 -11
  19. data/lib/abstract_controller.rb +21 -5
  20. data/lib/action_controller/api/api_rendering.rb +18 -0
  21. data/lib/action_controller/api.rb +154 -0
  22. data/lib/action_controller/base.rb +219 -155
  23. data/lib/action_controller/caching.rb +28 -68
  24. data/lib/action_controller/deprecator.rb +9 -0
  25. data/lib/action_controller/form_builder.rb +55 -0
  26. data/lib/action_controller/log_subscriber.rb +35 -22
  27. data/lib/action_controller/metal/allow_browser.rb +119 -0
  28. data/lib/action_controller/metal/basic_implicit_render.rb +17 -0
  29. data/lib/action_controller/metal/conditional_get.rb +259 -122
  30. data/lib/action_controller/metal/content_security_policy.rb +86 -0
  31. data/lib/action_controller/metal/cookies.rb +9 -5
  32. data/lib/action_controller/metal/data_streaming.rb +87 -104
  33. data/lib/action_controller/metal/default_headers.rb +21 -0
  34. data/lib/action_controller/metal/etag_with_flash.rb +22 -0
  35. data/lib/action_controller/metal/etag_with_template_digest.rb +35 -26
  36. data/lib/action_controller/metal/exceptions.rb +71 -24
  37. data/lib/action_controller/metal/flash.rb +26 -19
  38. data/lib/action_controller/metal/head.rb +45 -36
  39. data/lib/action_controller/metal/helpers.rb +80 -64
  40. data/lib/action_controller/metal/http_authentication.rb +297 -244
  41. data/lib/action_controller/metal/implicit_render.rb +57 -9
  42. data/lib/action_controller/metal/instrumentation.rb +76 -64
  43. data/lib/action_controller/metal/live.rb +238 -176
  44. data/lib/action_controller/metal/logging.rb +22 -0
  45. data/lib/action_controller/metal/mime_responds.rb +177 -166
  46. data/lib/action_controller/metal/parameter_encoding.rb +84 -0
  47. data/lib/action_controller/metal/params_wrapper.rb +145 -118
  48. data/lib/action_controller/metal/permissions_policy.rb +38 -0
  49. data/lib/action_controller/metal/rate_limiting.rb +62 -0
  50. data/lib/action_controller/metal/redirecting.rb +203 -64
  51. data/lib/action_controller/metal/renderers.rb +108 -65
  52. data/lib/action_controller/metal/rendering.rb +216 -56
  53. data/lib/action_controller/metal/request_forgery_protection.rb +496 -163
  54. data/lib/action_controller/metal/rescue.rb +19 -21
  55. data/lib/action_controller/metal/streaming.rb +179 -138
  56. data/lib/action_controller/metal/strong_parameters.rb +1058 -382
  57. data/lib/action_controller/metal/testing.rb +11 -17
  58. data/lib/action_controller/metal/url_for.rb +37 -21
  59. data/lib/action_controller/metal.rb +236 -138
  60. data/lib/action_controller/railtie.rb +89 -11
  61. data/lib/action_controller/railties/helpers.rb +5 -1
  62. data/lib/action_controller/renderer.rb +161 -0
  63. data/lib/action_controller/template_assertions.rb +13 -0
  64. data/lib/action_controller/test_case.rb +425 -497
  65. data/lib/action_controller.rb +44 -22
  66. data/lib/action_dispatch/constants.rb +34 -0
  67. data/lib/action_dispatch/deprecator.rb +9 -0
  68. data/lib/action_dispatch/http/cache.rb +119 -63
  69. data/lib/action_dispatch/http/content_disposition.rb +47 -0
  70. data/lib/action_dispatch/http/content_security_policy.rb +364 -0
  71. data/lib/action_dispatch/http/filter_parameters.rb +36 -34
  72. data/lib/action_dispatch/http/filter_redirect.rb +24 -12
  73. data/lib/action_dispatch/http/headers.rb +66 -31
  74. data/lib/action_dispatch/http/mime_negotiation.rb +106 -75
  75. data/lib/action_dispatch/http/mime_type.rb +196 -136
  76. data/lib/action_dispatch/http/mime_types.rb +25 -7
  77. data/lib/action_dispatch/http/parameters.rb +97 -45
  78. data/lib/action_dispatch/http/permissions_policy.rb +187 -0
  79. data/lib/action_dispatch/http/rack_cache.rb +6 -0
  80. data/lib/action_dispatch/http/request.rb +299 -170
  81. data/lib/action_dispatch/http/response.rb +311 -160
  82. data/lib/action_dispatch/http/upload.rb +52 -23
  83. data/lib/action_dispatch/http/url.rb +201 -125
  84. data/lib/action_dispatch/journey/formatter.rb +110 -50
  85. data/lib/action_dispatch/journey/gtg/builder.rb +37 -50
  86. data/lib/action_dispatch/journey/gtg/simulator.rb +20 -17
  87. data/lib/action_dispatch/journey/gtg/transition_table.rb +96 -36
  88. data/lib/action_dispatch/journey/nfa/dot.rb +5 -14
  89. data/lib/action_dispatch/journey/nodes/node.rb +100 -20
  90. data/lib/action_dispatch/journey/parser.rb +19 -17
  91. data/lib/action_dispatch/journey/parser.y +4 -3
  92. data/lib/action_dispatch/journey/parser_extras.rb +14 -4
  93. data/lib/action_dispatch/journey/path/pattern.rb +79 -63
  94. data/lib/action_dispatch/journey/route.rb +108 -44
  95. data/lib/action_dispatch/journey/router/utils.rb +41 -29
  96. data/lib/action_dispatch/journey/router.rb +64 -57
  97. data/lib/action_dispatch/journey/routes.rb +23 -21
  98. data/lib/action_dispatch/journey/scanner.rb +28 -17
  99. data/lib/action_dispatch/journey/visitors.rb +100 -54
  100. data/lib/action_dispatch/journey/visualizer/fsm.js +49 -24
  101. data/lib/action_dispatch/journey/visualizer/index.html.erb +1 -1
  102. data/lib/action_dispatch/journey.rb +7 -5
  103. data/lib/action_dispatch/log_subscriber.rb +25 -0
  104. data/lib/action_dispatch/middleware/actionable_exceptions.rb +46 -0
  105. data/lib/action_dispatch/middleware/assume_ssl.rb +27 -0
  106. data/lib/action_dispatch/middleware/callbacks.rb +7 -6
  107. data/lib/action_dispatch/middleware/cookies.rb +471 -328
  108. data/lib/action_dispatch/middleware/debug_exceptions.rb +149 -66
  109. data/lib/action_dispatch/middleware/debug_locks.rb +129 -0
  110. data/lib/action_dispatch/middleware/debug_view.rb +73 -0
  111. data/lib/action_dispatch/middleware/exception_wrapper.rb +275 -73
  112. data/lib/action_dispatch/middleware/executor.rb +32 -0
  113. data/lib/action_dispatch/middleware/flash.rb +143 -101
  114. data/lib/action_dispatch/middleware/host_authorization.rb +171 -0
  115. data/lib/action_dispatch/middleware/public_exceptions.rb +36 -27
  116. data/lib/action_dispatch/middleware/reloader.rb +10 -92
  117. data/lib/action_dispatch/middleware/remote_ip.rb +133 -107
  118. data/lib/action_dispatch/middleware/request_id.rb +29 -15
  119. data/lib/action_dispatch/middleware/server_timing.rb +78 -0
  120. data/lib/action_dispatch/middleware/session/abstract_store.rb +49 -27
  121. data/lib/action_dispatch/middleware/session/cache_store.rb +33 -16
  122. data/lib/action_dispatch/middleware/session/cookie_store.rb +86 -80
  123. data/lib/action_dispatch/middleware/session/mem_cache_store.rb +15 -3
  124. data/lib/action_dispatch/middleware/show_exceptions.rb +66 -36
  125. data/lib/action_dispatch/middleware/ssl.rb +134 -36
  126. data/lib/action_dispatch/middleware/stack.rb +109 -44
  127. data/lib/action_dispatch/middleware/static.rb +159 -90
  128. data/lib/action_dispatch/middleware/templates/rescues/_actions.html.erb +13 -0
  129. data/lib/action_dispatch/middleware/templates/rescues/_actions.text.erb +0 -0
  130. data/lib/action_dispatch/middleware/templates/rescues/_message_and_suggestions.html.erb +22 -0
  131. data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb +7 -24
  132. data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.text.erb +1 -1
  133. data/lib/action_dispatch/middleware/templates/rescues/_source.html.erb +36 -0
  134. data/lib/action_dispatch/middleware/templates/rescues/_source.text.erb +8 -0
  135. data/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb +46 -36
  136. data/lib/action_dispatch/middleware/templates/rescues/blocked_host.html.erb +12 -0
  137. data/lib/action_dispatch/middleware/templates/rescues/blocked_host.text.erb +9 -0
  138. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb +26 -7
  139. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.text.erb +3 -3
  140. data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.html.erb +24 -0
  141. data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.text.erb +16 -0
  142. data/lib/action_dispatch/middleware/templates/rescues/layout.erb +139 -15
  143. data/lib/action_dispatch/middleware/templates/rescues/missing_exact_template.html.erb +23 -0
  144. data/lib/action_dispatch/middleware/templates/rescues/missing_exact_template.text.erb +3 -0
  145. data/lib/action_dispatch/middleware/templates/rescues/missing_template.html.erb +6 -6
  146. data/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb +7 -7
  147. data/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb +9 -9
  148. data/lib/action_dispatch/middleware/templates/rescues/template_error.text.erb +1 -1
  149. data/lib/action_dispatch/middleware/templates/rescues/unknown_action.html.erb +4 -4
  150. data/lib/action_dispatch/middleware/templates/rescues/unknown_action.text.erb +1 -1
  151. data/lib/action_dispatch/middleware/templates/routes/_route.html.erb +7 -4
  152. data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +125 -93
  153. data/lib/action_dispatch/railtie.rb +44 -16
  154. data/lib/action_dispatch/request/session.rb +159 -69
  155. data/lib/action_dispatch/request/utils.rb +97 -23
  156. data/lib/action_dispatch/routing/endpoint.rb +11 -2
  157. data/lib/action_dispatch/routing/inspector.rb +195 -106
  158. data/lib/action_dispatch/routing/mapper.rb +1338 -955
  159. data/lib/action_dispatch/routing/polymorphic_routes.rb +234 -201
  160. data/lib/action_dispatch/routing/redirection.rb +78 -51
  161. data/lib/action_dispatch/routing/route_set.rb +460 -374
  162. data/lib/action_dispatch/routing/routes_proxy.rb +36 -12
  163. data/lib/action_dispatch/routing/url_for.rb +172 -124
  164. data/lib/action_dispatch/routing.rb +159 -158
  165. data/lib/action_dispatch/system_test_case.rb +206 -0
  166. data/lib/action_dispatch/system_testing/browser.rb +84 -0
  167. data/lib/action_dispatch/system_testing/driver.rb +85 -0
  168. data/lib/action_dispatch/system_testing/server.rb +33 -0
  169. data/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb +164 -0
  170. data/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb +23 -0
  171. data/lib/action_dispatch/testing/assertion_response.rb +48 -0
  172. data/lib/action_dispatch/testing/assertions/response.rb +71 -39
  173. data/lib/action_dispatch/testing/assertions/routing.rb +228 -103
  174. data/lib/action_dispatch/testing/assertions.rb +9 -6
  175. data/lib/action_dispatch/testing/integration.rb +486 -306
  176. data/lib/action_dispatch/testing/request_encoder.rb +60 -0
  177. data/lib/action_dispatch/testing/test_helpers/page_dump_helper.rb +35 -0
  178. data/lib/action_dispatch/testing/test_process.rb +35 -22
  179. data/lib/action_dispatch/testing/test_request.rb +29 -34
  180. data/lib/action_dispatch/testing/test_response.rb +48 -15
  181. data/lib/action_dispatch.rb +82 -40
  182. data/lib/action_pack/gem_version.rb +8 -4
  183. data/lib/action_pack/version.rb +6 -2
  184. data/lib/action_pack.rb +21 -18
  185. metadata +146 -56
  186. data/lib/action_controller/caching/fragments.rb +0 -103
  187. data/lib/action_controller/metal/force_ssl.rb +0 -97
  188. data/lib/action_controller/metal/hide_actions.rb +0 -40
  189. data/lib/action_controller/metal/rack_delegation.rb +0 -32
  190. data/lib/action_controller/middleware.rb +0 -39
  191. data/lib/action_controller/model_naming.rb +0 -12
  192. data/lib/action_dispatch/http/parameter_filter.rb +0 -72
  193. data/lib/action_dispatch/journey/backwards.rb +0 -5
  194. data/lib/action_dispatch/journey/nfa/builder.rb +0 -76
  195. data/lib/action_dispatch/journey/nfa/simulator.rb +0 -47
  196. data/lib/action_dispatch/journey/nfa/transition_table.rb +0 -163
  197. data/lib/action_dispatch/journey/router/strexp.rb +0 -27
  198. data/lib/action_dispatch/middleware/params_parser.rb +0 -60
  199. data/lib/action_dispatch/middleware/templates/rescues/_source.erb +0 -27
  200. data/lib/action_dispatch/testing/assertions/dom.rb +0 -3
  201. data/lib/action_dispatch/testing/assertions/selector.rb +0 -3
  202. data/lib/action_dispatch/testing/assertions/tag.rb +0 -3
@@ -1,197 +1,224 @@
1
- require 'action_view'
1
+ # frozen_string_literal: true
2
+
3
+ # :markup: markdown
4
+
5
+ require "action_view"
2
6
  require "action_controller/log_subscriber"
3
7
  require "action_controller/metal/params_wrapper"
4
8
 
5
9
  module ActionController
6
- # Action Controllers are the core of a web request in \Rails. They are made up of one or more actions that are executed
7
- # on request and then either it renders a template or redirects to another action. An action is defined as a public method
8
- # on the controller, which will automatically be made accessible to the web-server through \Rails Routes.
10
+ # # Action Controller Base
9
11
  #
10
- # By default, only the ApplicationController in a \Rails application inherits from <tt>ActionController::Base</tt>. All other
11
- # controllers in turn inherit from ApplicationController. This gives you one class to configure things such as
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.
17
+ #
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
12
21
  # request forgery protection and filtering of sensitive request parameters.
13
22
  #
14
23
  # A sample controller could look like this:
15
24
  #
16
- # class PostsController < ApplicationController
17
- # def index
18
- # @posts = Post.all
19
- # end
25
+ # class PostsController < ApplicationController
26
+ # def index
27
+ # @posts = Post.all
28
+ # end
20
29
  #
21
- # def create
22
- # @post = Post.create params[:post]
23
- # redirect_to posts_path
30
+ # def create
31
+ # @post = Post.create params[:post]
32
+ # redirect_to posts_path
33
+ # end
24
34
  # end
25
- # end
26
- #
27
- # Actions, by default, render a template in the <tt>app/views</tt> directory corresponding to the name of the controller and action
28
- # after executing code in the action. For example, the +index+ action of the PostsController would render the
29
- # template <tt>app/views/posts/index.html.erb</tt> by default after populating the <tt>@posts</tt> instance variable.
30
35
  #
31
- # Unlike index, the create action will not render a template. After performing its main purpose (creating a
32
- # new post), it initiates a redirect instead. This redirect works by returning an external
33
- # "302 Moved" HTTP response that takes the user to the index action.
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
- # These two methods represent the two basic action archetypes used in Action Controllers. Get-and-show and do-and-redirect.
36
- # Most actions are variations on these themes.
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.
37
46
  #
38
- # == Requests
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.
39
50
  #
40
- # For every request, the router determines the value of the +controller+ and +action+ keys. These determine which controller
41
- # and action are called. The remaining request parameters, the session (if one is available), and the full request with
42
- # all the HTTP headers are made available to the action through accessor methods. Then the action is performed.
51
+ # ## Requests
43
52
  #
44
- # The full request object is available via the request accessor and is primarily used to query for HTTP headers:
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.
45
58
  #
46
- # def server_ip
47
- # location = request.env["REMOTE_ADDR"]
48
- # render plain: "This server hosted at #{location}"
49
- # end
59
+ # The full request object is available via the request accessor and is primarily
60
+ # used to query for HTTP headers:
50
61
  #
51
- # == Parameters
62
+ # def server_ip
63
+ # location = request.env["REMOTE_ADDR"]
64
+ # render plain: "This server hosted at #{location}"
65
+ # end
52
66
  #
53
- # All request parameters, whether they come from a GET or POST request, or from the URL, are available through the params method
54
- # which returns a hash. For example, an action that was performed through <tt>/posts?category=All&limit=5</tt> will include
55
- # <tt>{ "category" => "All", "limit" => "5" }</tt> in params.
67
+ # ## Parameters
56
68
  #
57
- # It's also possible to construct multi-dimensional parameter hashes by specifying keys using brackets, such as:
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`.
58
74
  #
59
- # <input type="text" name="post[name]" value="david">
60
- # <input type="text" name="post[address]" value="hyacintvej">
75
+ # It's also possible to construct multi-dimensional parameter hashes by
76
+ # specifying keys using brackets, such as:
61
77
  #
62
- # A request stemming from a form holding these inputs will include <tt>{ "post" => { "name" => "david", "address" => "hyacintvej" } }</tt>.
63
- # If the address input had been named <tt>post[address][street]</tt>, the params would have included
64
- # <tt>{ "post" => { "address" => { "street" => "hyacintvej" } } }</tt>. There's no limit to the depth of the nesting.
78
+ # <input type="text" name="post[name]" value="david">
79
+ # <input type="text" name="post[address]" value="hyacintvej">
65
80
  #
66
- # == Sessions
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.
67
86
  #
68
- # Sessions allow you to store objects in between requests. This is useful for objects that are not yet ready to be persisted,
69
- # such as a Signup object constructed in a multi-paged process, or objects that don't change much and are needed all the time, such
70
- # as a User object for a system that requires login. The session should not be used, however, as a cache for objects where it's likely
71
- # they could be changed unknowingly. It's usually too much work to keep it all synchronized -- something databases already excel at.
87
+ # ## Sessions
72
88
  #
73
- # You can place objects in the session by using the <tt>session</tt> method, which accesses a hash:
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.
74
96
  #
75
- # session[:person] = Person.authenticate(user_name, password)
97
+ # You can place objects in the session by using the `session` method, which
98
+ # accesses a hash:
76
99
  #
77
- # And retrieved again through the same hash:
100
+ # session[:person] = Person.authenticate(user_name, password)
78
101
  #
79
- # Hello #{session[:person]}
102
+ # You can retrieve it again through the same hash:
80
103
  #
81
- # For removing objects from the session, you can either assign a single key to +nil+:
104
+ # "Hello #{session[:person]}"
82
105
  #
83
- # # removes :person from session
84
- # session[:person] = nil
106
+ # For removing objects from the session, you can either assign a single key to
107
+ # `nil`:
85
108
  #
86
- # or you can remove the entire session with +reset_session+.
109
+ # # removes :person from session
110
+ # session[:person] = nil
87
111
  #
88
- # Sessions are stored by default in a browser cookie that's cryptographically signed, but unencrypted.
89
- # This prevents the user from tampering with the session but also allows them to see its contents.
112
+ # or you can remove the entire session with `reset_session`.
90
113
  #
91
- # Do not put secret information in cookie-based sessions!
114
+ # By default, sessions are stored in an encrypted browser cookie (see
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.
92
119
  #
93
- # == Responses
120
+ # ## Responses
94
121
  #
95
- # Each action results in a response, which holds the headers and document to be sent to the user's browser. The actual response
96
- # object is generated automatically through the use of renders and redirects and requires no user intervention.
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.
97
126
  #
98
- # == Renders
127
+ # ## Renders
99
128
  #
100
- # Action Controller sends content to the user by using one of five rendering methods. The most versatile and common is the rendering
101
- # of a template. Included in the Action Pack is the Action View, which enables rendering of ERB templates. It's automatically configured.
102
- # The controller passes objects to the view by assigning instance variables:
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:
103
134
  #
104
- # def show
105
- # @post = Post.find(params[:id])
106
- # end
135
+ # def show
136
+ # @post = Post.find(params[:id])
137
+ # end
107
138
  #
108
139
  # Which are then automatically available to the view:
109
140
  #
110
- # Title: <%= @post.title %>
141
+ # Title: <%= @post.title %>
111
142
  #
112
- # You don't have to rely on the automated rendering. For example, actions that could result in the rendering of different templates
113
- # will use the manual rendering methods:
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:
114
146
  #
115
- # def search
116
- # @results = Search.find(params[:query])
117
- # case @results.count
118
- # when 0 then render action: "no_results"
119
- # when 1 then render action: "show"
120
- # when 2..10 then render action: "show_many"
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
121
154
  # end
122
- # end
123
155
  #
124
156
  # Read more about writing ERB and Builder templates in ActionView::Base.
125
157
  #
126
- # == Redirects
158
+ # ## Redirects
127
159
  #
128
- # Redirects are used to move from one action to another. For example, after a <tt>create</tt> action, which stores a blog entry to the
129
- # database, we might like to show the user the new entry. Because we're following good DRY principles (Don't Repeat Yourself), we're
130
- # going to reuse (and redirect to) a <tt>show</tt> action that we'll assume has already been created. The code might look like this:
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:
131
166
  #
132
- # def create
133
- # @entry = Entry.new(params[:entry])
134
- # if @entry.save
135
- # # The entry was saved correctly, redirect to show
136
- # redirect_to action: 'show', id: @entry.id
137
- # else
138
- # # things didn't go so well, do something else
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
139
175
  # end
140
- # end
141
176
  #
142
- # In this case, after saving our new entry to the database, the user is redirected to the <tt>show</tt> method, which is then executed.
143
- # Note that this is an external HTTP-level redirection which will cause the browser to make a second request (a GET to the show action),
144
- # and not some internal re-routing which calls both "create" and then "show" within one request.
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.
145
182
  #
146
- # Learn more about <tt>redirect_to</tt> and what options you have in ActionController::Redirecting.
183
+ # Learn more about `redirect_to` and what options you have in
184
+ # ActionController::Redirecting.
147
185
  #
148
- # == Calling multiple redirects or renders
186
+ # ## Calling multiple redirects or renders
149
187
  #
150
- # An action may contain only a single render or a single redirect. Attempting to try to do either again will result in a DoubleRenderError:
188
+ # An action may perform only a single render or a single redirect. Attempting to
189
+ # do either again will result in a DoubleRenderError:
151
190
  #
152
- # def do_something
153
- # redirect_to action: "elsewhere"
154
- # render action: "overthere" # raises DoubleRenderError
155
- # end
191
+ # def do_something
192
+ # redirect_to action: "elsewhere"
193
+ # render action: "overthere" # raises DoubleRenderError
194
+ # end
156
195
  #
157
- # If you need to redirect on the condition of something, then be sure to add "and return" to halt execution.
196
+ # If you need to redirect on the condition of something, then be sure to add
197
+ # "return" to halt execution.
158
198
  #
159
- # def do_something
160
- # redirect_to(action: "elsewhere") and return if monkeys.nil?
161
- # render action: "overthere" # won't be called if monkeys is nil
162
- # end
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
163
206
  #
164
207
  class Base < Metal
165
208
  abstract!
166
209
 
167
- # We document the request and response methods here because albeit they are
168
- # implemented in ActionController::Metal, the type of the returned objects
169
- # is unknown at that level.
170
-
171
- ##
172
- # :method: request
173
- #
174
- # Returns an ActionDispatch::Request instance that represents the
175
- # current request.
176
-
177
- ##
178
- # :method: response
179
- #
180
- # Returns an ActionDispatch::Response that represents the current
181
- # response.
182
-
183
210
  # Shortcut helper that returns all the modules included in
184
211
  # ActionController::Base except the ones passed as arguments:
185
212
  #
186
- # class MyBaseController < ActionController::Metal
187
- # ActionController::Base.without_modules(:ParamsWrapper, :Streaming).each do |left|
188
- # include left
213
+ # class MyBaseController < ActionController::Metal
214
+ # ActionController::Base.without_modules(:ParamsWrapper, :Streaming).each do |left|
215
+ # include left
216
+ # end
189
217
  # end
190
- # end
191
218
  #
192
- # This gives better control over what you want to exclude and makes it
193
- # easier to create a bare controller class, instead of listing the modules
194
- # required manually.
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.
195
222
  def self.without_modules(*modules)
196
223
  modules = modules.map do |m|
197
224
  m.is_a?(Symbol) ? ActionController.const_get(m) : m
@@ -204,9 +231,7 @@ module ActionController
204
231
  AbstractController::Rendering,
205
232
  AbstractController::Translation,
206
233
  AbstractController::AssetPaths,
207
-
208
234
  Helpers,
209
- HideActions,
210
235
  UrlFor,
211
236
  Redirecting,
212
237
  ActionView::Layouts,
@@ -214,55 +239,94 @@ module ActionController
214
239
  Renderers::All,
215
240
  ConditionalGet,
216
241
  EtagWithTemplateDigest,
217
- RackDelegation,
242
+ EtagWithFlash,
218
243
  Caching,
219
244
  MimeResponds,
220
245
  ImplicitRender,
221
246
  StrongParameters,
222
-
247
+ ParameterEncoding,
223
248
  Cookies,
224
249
  Flash,
250
+ FormBuilder,
225
251
  RequestForgeryProtection,
226
- ForceSSL,
252
+ ContentSecurityPolicy,
253
+ PermissionsPolicy,
254
+ RateLimiting,
255
+ AllowBrowser,
227
256
  Streaming,
228
257
  DataStreaming,
229
258
  HttpAuthentication::Basic::ControllerMethods,
230
259
  HttpAuthentication::Digest::ControllerMethods,
231
260
  HttpAuthentication::Token::ControllerMethods,
232
-
233
- # Before callbacks should also be executed the earliest as possible, so
234
- # also include them at the bottom.
261
+ DefaultHeaders,
262
+ Logging,
235
263
  AbstractController::Callbacks,
236
-
237
- # Append rescue at the bottom to wrap as much as possible.
238
264
  Rescue,
239
-
240
- # Add instrumentations hooks at the bottom, to ensure they instrument
241
- # all the methods properly.
242
265
  Instrumentation,
243
-
244
- # Params wrapper should come before instrumentation so they are
245
- # properly showed in logs
246
266
  ParamsWrapper
247
267
  ]
248
268
 
249
- MODULES.each do |mod|
250
- include mod
251
- end
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:
315
+ setup_renderer!
252
316
 
253
317
  # Define some internal variables that should not be propagated to the view.
254
- PROTECTED_IVARS = AbstractController::Rendering::DEFAULT_PROTECTED_INSTANCE_VARIABLES + [
255
- :@_status, :@_headers, :@_params, :@_env, :@_response, :@_request,
256
- :@_view_runtime, :@_stream, :@_url_options, :@_action_has_layout ]
257
-
258
- def _protected_ivars # :nodoc:
259
- PROTECTED_IVARS
260
- end
318
+ PROTECTED_IVARS = AbstractController::Rendering::DEFAULT_PROTECTED_INSTANCE_VARIABLES + %i(
319
+ @_params @_response @_request @_config @_url_options @_action_has_layout @_view_context_class
320
+ @_view_renderer @_lookup_context @_routes @_view_runtime @_db_runtime @_helper_proxy
321
+ @_marked_for_same_origin_verification @_rendered_format
322
+ )
261
323
 
262
- def self.protected_instance_variables
324
+ def _protected_ivars
263
325
  PROTECTED_IVARS
264
326
  end
327
+ private :_protected_ivars
265
328
 
329
+ ActiveSupport.run_load_hooks(:action_controller_base, self)
266
330
  ActiveSupport.run_load_hooks(:action_controller, self)
267
331
  end
268
332
  end
@@ -1,89 +1,49 @@
1
- require 'fileutils'
2
- require 'uri'
3
- require 'set'
1
+ # frozen_string_literal: true
2
+
3
+ # :markup: markdown
4
4
 
5
5
  module ActionController
6
- # \Caching is a cheap way of speeding up slow applications by keeping the result of
7
- # calculations, renderings, and database calls around for subsequent requests.
6
+ # # Action Controller Caching
7
+ #
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
- # Note: To turn off all caching, set
12
- # config.action_controller.perform_caching = false
14
+ # Note: To turn off all caching provided by Action Controller, set
15
+ # config.action_controller.perform_caching = false
13
16
  #
14
- # == \Caching stores
17
+ # ## Caching stores
15
18
  #
16
- # All the caching stores from ActiveSupport::Cache are available to be used as backends
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
- # config.action_controller.cache_store = :memory_store
22
- # config.action_controller.cache_store = :file_store, '/path/to/cache/directory'
23
- # config.action_controller.cache_store = :mem_cache_store, 'localhost'
24
- # config.action_controller.cache_store = :mem_cache_store, Memcached::Rails.new('localhost:11211')
25
- # config.action_controller.cache_store = MyOwnStore.new('parameter')
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
- 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
54
31
 
55
32
  included do
56
- extend ConfigMethods
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)
33
+ include AbstractController::Caching
67
34
  end
68
35
 
69
- module ClassMethods
70
- def view_cache_dependency(&dependency)
71
- self._view_cache_dependencies += [dependency]
36
+ private
37
+ def instrument_payload(key)
38
+ {
39
+ controller: controller_name,
40
+ action: action_name,
41
+ key: key
42
+ }
72
43
  end
73
- end
74
-
75
- def view_cache_dependencies
76
- self.class._view_cache_dependencies.map { |dep| instance_exec(&dep) }.compact
77
- end
78
44
 
79
- protected
80
- # Convenience accessor.
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
45
+ def instrument_name
46
+ "action_controller"
87
47
  end
88
48
  end
89
49
  end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ # :markup: markdown
4
+
5
+ module ActionController
6
+ def self.deprecator # :nodoc:
7
+ AbstractController.deprecator
8
+ end
9
+ end