actionpack 7.0.8.7 → 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.
Files changed (171) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +90 -537
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +2 -2
  5. data/lib/abstract_controller/asset_paths.rb +2 -0
  6. data/lib/abstract_controller/base.rb +119 -106
  7. data/lib/abstract_controller/caching/fragments.rb +51 -52
  8. data/lib/abstract_controller/caching.rb +2 -0
  9. data/lib/abstract_controller/callbacks.rb +94 -67
  10. data/lib/abstract_controller/collector.rb +6 -6
  11. data/lib/abstract_controller/deprecator.rb +9 -0
  12. data/lib/abstract_controller/error.rb +2 -0
  13. data/lib/abstract_controller/helpers.rb +121 -91
  14. data/lib/abstract_controller/logger.rb +2 -0
  15. data/lib/abstract_controller/railties/routes_helpers.rb +3 -16
  16. data/lib/abstract_controller/rendering.rb +14 -13
  17. data/lib/abstract_controller/translation.rb +12 -30
  18. data/lib/abstract_controller/url_for.rb +9 -5
  19. data/lib/abstract_controller.rb +8 -0
  20. data/lib/action_controller/api/api_rendering.rb +2 -0
  21. data/lib/action_controller/api.rb +78 -73
  22. data/lib/action_controller/base.rb +199 -141
  23. data/lib/action_controller/caching.rb +16 -11
  24. data/lib/action_controller/deprecator.rb +9 -0
  25. data/lib/action_controller/form_builder.rb +21 -16
  26. data/lib/action_controller/log_subscriber.rb +19 -5
  27. data/lib/action_controller/metal/allow_browser.rb +123 -0
  28. data/lib/action_controller/metal/basic_implicit_render.rb +2 -0
  29. data/lib/action_controller/metal/conditional_get.rb +187 -174
  30. data/lib/action_controller/metal/content_security_policy.rb +26 -25
  31. data/lib/action_controller/metal/cookies.rb +4 -2
  32. data/lib/action_controller/metal/data_streaming.rb +65 -54
  33. data/lib/action_controller/metal/default_headers.rb +6 -2
  34. data/lib/action_controller/metal/etag_with_flash.rb +4 -0
  35. data/lib/action_controller/metal/etag_with_template_digest.rb +18 -14
  36. data/lib/action_controller/metal/exceptions.rb +19 -9
  37. data/lib/action_controller/metal/flash.rb +12 -10
  38. data/lib/action_controller/metal/head.rb +20 -16
  39. data/lib/action_controller/metal/helpers.rb +64 -67
  40. data/lib/action_controller/metal/http_authentication.rb +212 -199
  41. data/lib/action_controller/metal/implicit_render.rb +21 -17
  42. data/lib/action_controller/metal/instrumentation.rb +22 -12
  43. data/lib/action_controller/metal/live.rb +125 -92
  44. data/lib/action_controller/metal/logging.rb +6 -4
  45. data/lib/action_controller/metal/mime_responds.rb +151 -142
  46. data/lib/action_controller/metal/parameter_encoding.rb +34 -32
  47. data/lib/action_controller/metal/params_wrapper.rb +58 -58
  48. data/lib/action_controller/metal/permissions_policy.rb +14 -13
  49. data/lib/action_controller/metal/rate_limiting.rb +62 -0
  50. data/lib/action_controller/metal/redirecting.rb +110 -84
  51. data/lib/action_controller/metal/renderers.rb +50 -49
  52. data/lib/action_controller/metal/rendering.rb +103 -82
  53. data/lib/action_controller/metal/request_forgery_protection.rb +279 -161
  54. data/lib/action_controller/metal/rescue.rb +12 -8
  55. data/lib/action_controller/metal/streaming.rb +174 -132
  56. data/lib/action_controller/metal/strong_parameters.rb +598 -473
  57. data/lib/action_controller/metal/testing.rb +2 -0
  58. data/lib/action_controller/metal/url_for.rb +23 -14
  59. data/lib/action_controller/metal.rb +145 -61
  60. data/lib/action_controller/railtie.rb +25 -9
  61. data/lib/action_controller/railties/helpers.rb +2 -0
  62. data/lib/action_controller/renderer.rb +105 -66
  63. data/lib/action_controller/template_assertions.rb +4 -2
  64. data/lib/action_controller/test_case.rb +157 -128
  65. data/lib/action_controller.rb +17 -3
  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 +28 -29
  69. data/lib/action_dispatch/http/content_disposition.rb +2 -0
  70. data/lib/action_dispatch/http/content_security_policy.rb +48 -45
  71. data/lib/action_dispatch/http/filter_parameters.rb +18 -8
  72. data/lib/action_dispatch/http/filter_redirect.rb +22 -1
  73. data/lib/action_dispatch/http/headers.rb +23 -21
  74. data/lib/action_dispatch/http/mime_negotiation.rb +37 -48
  75. data/lib/action_dispatch/http/mime_type.rb +60 -30
  76. data/lib/action_dispatch/http/mime_types.rb +5 -1
  77. data/lib/action_dispatch/http/parameters.rb +12 -10
  78. data/lib/action_dispatch/http/permissions_policy.rb +32 -27
  79. data/lib/action_dispatch/http/rack_cache.rb +4 -0
  80. data/lib/action_dispatch/http/request.rb +132 -79
  81. data/lib/action_dispatch/http/response.rb +136 -103
  82. data/lib/action_dispatch/http/upload.rb +19 -15
  83. data/lib/action_dispatch/http/url.rb +75 -73
  84. data/lib/action_dispatch/journey/formatter.rb +19 -6
  85. data/lib/action_dispatch/journey/gtg/builder.rb +4 -3
  86. data/lib/action_dispatch/journey/gtg/simulator.rb +2 -0
  87. data/lib/action_dispatch/journey/gtg/transition_table.rb +10 -8
  88. data/lib/action_dispatch/journey/nfa/dot.rb +2 -0
  89. data/lib/action_dispatch/journey/nodes/node.rb +6 -5
  90. data/lib/action_dispatch/journey/parser.rb +4 -3
  91. data/lib/action_dispatch/journey/parser_extras.rb +2 -0
  92. data/lib/action_dispatch/journey/path/pattern.rb +18 -15
  93. data/lib/action_dispatch/journey/route.rb +12 -9
  94. data/lib/action_dispatch/journey/router/utils.rb +16 -15
  95. data/lib/action_dispatch/journey/router.rb +13 -10
  96. data/lib/action_dispatch/journey/routes.rb +6 -4
  97. data/lib/action_dispatch/journey/scanner.rb +4 -2
  98. data/lib/action_dispatch/journey/visitors.rb +2 -0
  99. data/lib/action_dispatch/journey.rb +2 -0
  100. data/lib/action_dispatch/log_subscriber.rb +25 -0
  101. data/lib/action_dispatch/middleware/actionable_exceptions.rb +7 -6
  102. data/lib/action_dispatch/middleware/assume_ssl.rb +27 -0
  103. data/lib/action_dispatch/middleware/callbacks.rb +4 -0
  104. data/lib/action_dispatch/middleware/cookies.rb +192 -194
  105. data/lib/action_dispatch/middleware/debug_exceptions.rb +36 -27
  106. data/lib/action_dispatch/middleware/debug_locks.rb +18 -13
  107. data/lib/action_dispatch/middleware/debug_view.rb +9 -2
  108. data/lib/action_dispatch/middleware/exception_wrapper.rb +181 -27
  109. data/lib/action_dispatch/middleware/executor.rb +9 -1
  110. data/lib/action_dispatch/middleware/flash.rb +65 -46
  111. data/lib/action_dispatch/middleware/host_authorization.rb +22 -17
  112. data/lib/action_dispatch/middleware/public_exceptions.rb +12 -8
  113. data/lib/action_dispatch/middleware/reloader.rb +9 -5
  114. data/lib/action_dispatch/middleware/remote_ip.rb +88 -83
  115. data/lib/action_dispatch/middleware/request_id.rb +15 -8
  116. data/lib/action_dispatch/middleware/server_timing.rb +8 -6
  117. data/lib/action_dispatch/middleware/session/abstract_store.rb +7 -0
  118. data/lib/action_dispatch/middleware/session/cache_store.rb +14 -7
  119. data/lib/action_dispatch/middleware/session/cookie_store.rb +32 -25
  120. data/lib/action_dispatch/middleware/session/mem_cache_store.rb +9 -3
  121. data/lib/action_dispatch/middleware/show_exceptions.rb +42 -28
  122. data/lib/action_dispatch/middleware/ssl.rb +60 -45
  123. data/lib/action_dispatch/middleware/stack.rb +15 -9
  124. data/lib/action_dispatch/middleware/static.rb +40 -34
  125. data/lib/action_dispatch/middleware/templates/rescues/_actions.html.erb +2 -2
  126. data/lib/action_dispatch/middleware/templates/rescues/_message_and_suggestions.html.erb +4 -4
  127. data/lib/action_dispatch/middleware/templates/rescues/_source.html.erb +8 -1
  128. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb +7 -7
  129. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.text.erb +2 -2
  130. data/lib/action_dispatch/middleware/templates/rescues/layout.erb +17 -0
  131. data/lib/action_dispatch/middleware/templates/rescues/missing_exact_template.html.erb +16 -12
  132. data/lib/action_dispatch/middleware/templates/rescues/missing_template.html.erb +1 -1
  133. data/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb +3 -3
  134. data/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb +4 -4
  135. data/lib/action_dispatch/middleware/templates/rescues/unknown_action.html.erb +1 -1
  136. data/lib/action_dispatch/middleware/templates/rescues/unknown_action.text.erb +1 -1
  137. data/lib/action_dispatch/middleware/templates/routes/_route.html.erb +3 -0
  138. data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +47 -38
  139. data/lib/action_dispatch/railtie.rb +12 -4
  140. data/lib/action_dispatch/request/session.rb +39 -27
  141. data/lib/action_dispatch/request/utils.rb +10 -3
  142. data/lib/action_dispatch/routing/endpoint.rb +2 -0
  143. data/lib/action_dispatch/routing/inspector.rb +59 -9
  144. data/lib/action_dispatch/routing/mapper.rb +686 -639
  145. data/lib/action_dispatch/routing/polymorphic_routes.rb +70 -61
  146. data/lib/action_dispatch/routing/redirection.rb +52 -38
  147. data/lib/action_dispatch/routing/route_set.rb +106 -62
  148. data/lib/action_dispatch/routing/routes_proxy.rb +16 -19
  149. data/lib/action_dispatch/routing/url_for.rb +131 -122
  150. data/lib/action_dispatch/routing.rb +152 -150
  151. data/lib/action_dispatch/system_test_case.rb +91 -81
  152. data/lib/action_dispatch/system_testing/browser.rb +27 -19
  153. data/lib/action_dispatch/system_testing/driver.rb +16 -22
  154. data/lib/action_dispatch/system_testing/server.rb +2 -0
  155. data/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb +53 -31
  156. data/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb +2 -0
  157. data/lib/action_dispatch/testing/assertion_response.rb +9 -7
  158. data/lib/action_dispatch/testing/assertions/response.rb +36 -26
  159. data/lib/action_dispatch/testing/assertions/routing.rb +203 -95
  160. data/lib/action_dispatch/testing/assertions.rb +5 -1
  161. data/lib/action_dispatch/testing/integration.rb +240 -229
  162. data/lib/action_dispatch/testing/request_encoder.rb +6 -1
  163. data/lib/action_dispatch/testing/test_helpers/page_dump_helper.rb +35 -0
  164. data/lib/action_dispatch/testing/test_process.rb +14 -9
  165. data/lib/action_dispatch/testing/test_request.rb +4 -2
  166. data/lib/action_dispatch/testing/test_response.rb +34 -19
  167. data/lib/action_dispatch.rb +52 -21
  168. data/lib/action_pack/gem_version.rb +6 -4
  169. data/lib/action_pack/version.rb +3 -1
  170. data/lib/action_pack.rb +18 -17
  171. metadata +86 -27
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # :markup: markdown
4
+
3
5
  require "abstract_controller/error"
4
6
  require "action_view"
5
7
  require "action_view/view_paths"
@@ -7,7 +9,7 @@ require "set"
7
9
 
8
10
  module AbstractController
9
11
  class DoubleRenderError < Error
10
- DEFAULT_MESSAGE = "Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirect, and at most once per action. Also note that neither redirect nor render terminate execution of the action, so if you want to exit an action after redirecting, you need to do something like \"redirect_to(...) and return\"."
12
+ DEFAULT_MESSAGE = "Render and/or redirect were called multiple times in this action. Please note that you may only call render OR redirect, and at most once per action. Also note that neither redirect nor render terminate execution of the action, so if you want to exit an action after redirecting, you need to do something like \"redirect_to(...); return\"."
11
13
 
12
14
  def initialize(message = nil)
13
15
  super(message || DEFAULT_MESSAGE)
@@ -19,9 +21,9 @@ module AbstractController
19
21
  include ActionView::ViewPaths
20
22
 
21
23
  # Normalizes arguments and options, and then delegates to render_to_body and
22
- # sticks the result in <tt>self.response_body</tt>.
24
+ # sticks the result in `self.response_body`.
23
25
  #
24
- # Supported options depend on the underlying +render_to_body+ implementation.
26
+ # Supported options depend on the underlying `render_to_body` implementation.
25
27
  def render(*args, &block)
26
28
  options = _normalize_render(*args, &block)
27
29
  rendered_body = render_to_body(options)
@@ -35,11 +37,11 @@ module AbstractController
35
37
  end
36
38
 
37
39
  # Similar to #render, but only returns the rendered template as a string,
38
- # instead of setting +self.response_body+.
40
+ # instead of setting `self.response_body`.
39
41
  #
40
- # If a component extends the semantics of +response_body+ (as ActionController
41
- # extends it to be anything that responds to the method each), this method
42
- # needs to be overridden in order to still return a string.
42
+ # If a component extends the semantics of `response_body` (as ActionController
43
+ # extends it to be anything that responds to the method each), this method needs
44
+ # to be overridden in order to still return a string.
43
45
  def render_to_string(*args, &block)
44
46
  options = _normalize_render(*args, &block)
45
47
  render_to_body(options)
@@ -49,15 +51,15 @@ module AbstractController
49
51
  def render_to_body(options = {})
50
52
  end
51
53
 
52
- # Returns +Content-Type+ of rendered content.
54
+ # Returns `Content-Type` of rendered content.
53
55
  def rendered_format
54
56
  Mime[:text]
55
57
  end
56
58
 
57
59
  DEFAULT_PROTECTED_INSTANCE_VARIABLES = %i(@_action_name @_response_body @_formats @_prefixes)
58
60
 
59
- # This method should return a hash with assigns.
60
- # You can overwrite this configuration per controller.
61
+ # This method should return a hash with assigns. You can overwrite this
62
+ # configuration per controller.
61
63
  def view_assigns
62
64
  variables = instance_variables - _protected_ivars
63
65
 
@@ -67,9 +69,8 @@ module AbstractController
67
69
  end
68
70
 
69
71
  private
70
- # Normalize args by converting <tt>render "foo"</tt> to
71
- # <tt>render :action => "foo"</tt> and <tt>render "foo/bar"</tt> to
72
- # <tt>render :file => "foo/bar"</tt>.
72
+ # Normalize args by converting `render "foo"` to `render action: "foo"` and
73
+ # `render "foo/bar"` to `render file: "foo/bar"`.
73
74
  def _normalize_args(action = nil, options = {}) # :doc:
74
75
  if action.respond_to?(:permitted?)
75
76
  if action.permitted?
@@ -1,19 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # :markup: markdown
4
+
3
5
  require "active_support/html_safe_translation"
4
6
 
5
7
  module AbstractController
6
8
  module Translation
7
- mattr_accessor :raise_on_missing_translations, default: false
8
-
9
- # Delegates to <tt>I18n.translate</tt>.
9
+ # Delegates to `I18n.translate`.
10
10
  #
11
11
  # When the given key starts with a period, it will be scoped by the current
12
- # controller and action. So if you call <tt>translate(".foo")</tt> from
13
- # <tt>PeopleController#index</tt>, it will convert the call to
14
- # <tt>I18n.translate("people.index.foo")</tt>. This makes it less repetitive
15
- # to translate many keys within the same controller / action and gives you a
16
- # simple framework for scoping them consistently.
12
+ # controller and action. So if you call `translate(".foo")` from
13
+ # `PeopleController#index`, it will convert the call to
14
+ # `I18n.translate("people.index.foo")`. This makes it less repetitive to
15
+ # translate many keys within the same controller / action and gives you a simple
16
+ # framework for scoping them consistently.
17
17
  def translate(key, **options)
18
18
  if key&.start_with?(".")
19
19
  path = controller_path.tr("/", ".")
@@ -23,38 +23,20 @@ module AbstractController
23
23
  key = "#{path}.#{action_name}#{key}"
24
24
  end
25
25
 
26
- i18n_raise = options.fetch(:raise, self.raise_on_missing_translations)
27
-
28
- if options[:default]
29
- options[:default] = [options[:default]] unless options[:default].is_a?(Array)
30
- options[:default] = options[:default].map do |value|
26
+ if options[:default] && ActiveSupport::HtmlSafeTranslation.html_safe_translation_key?(key)
27
+ options[:default] = Array(options[:default]).map do |value|
31
28
  value.is_a?(String) ? ERB::Util.html_escape(value) : value
32
29
  end
33
30
  end
34
31
 
35
- unless i18n_raise
36
- options[:default] = [] unless options[:default]
37
- options[:default] << MISSING_TRANSLATION
38
- end
39
-
40
- result = ActiveSupport::HtmlSafeTranslation.translate(key, **options, raise: i18n_raise)
41
-
42
- if result == MISSING_TRANSLATION
43
- +"translation missing: #{key}"
44
- else
45
- result
46
- end
32
+ ActiveSupport::HtmlSafeTranslation.translate(key, **options)
47
33
  end
48
34
  alias :t :translate
49
35
 
50
- # Delegates to <tt>I18n.localize</tt>.
36
+ # Delegates to `I18n.localize`.
51
37
  def localize(object, **options)
52
38
  I18n.localize(object, **options)
53
39
  end
54
40
  alias :l :localize
55
-
56
- private
57
- MISSING_TRANSLATION = -(2**60)
58
- private_constant :MISSING_TRANSLATION
59
41
  end
60
42
  end
@@ -1,12 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # :markup: markdown
4
+
3
5
  module AbstractController
4
- # Includes +url_for+ into the host class (e.g. an abstract controller or mailer). The class
5
- # has to provide a +RouteSet+ by implementing the <tt>_routes</tt> methods. Otherwise, an
6
- # exception will be raised.
6
+ # # URL For
7
+ #
8
+ # Includes `url_for` into the host class (e.g. an abstract controller or
9
+ # mailer). The class has to provide a `RouteSet` by implementing the `_routes`
10
+ # methods. Otherwise, an exception will be raised.
7
11
  #
8
- # Note that this module is completely decoupled from HTTP - the only requirement is a valid
9
- # <tt>_routes</tt> implementation.
12
+ # Note that this module is completely decoupled from HTTP - the only requirement
13
+ # is a valid `_routes` implementation.
10
14
  module UrlFor
11
15
  extend ActiveSupport::Concern
12
16
  include ActionDispatch::Routing::UrlFor
@@ -1,9 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # :markup: markdown
4
+
3
5
  require "action_pack"
4
6
  require "active_support"
5
7
  require "active_support/rails"
6
8
  require "active_support/i18n"
9
+ require "abstract_controller/deprecator"
7
10
 
8
11
  module AbstractController
9
12
  extend ActiveSupport::Autoload
@@ -24,5 +27,10 @@ module AbstractController
24
27
  def self.eager_load!
25
28
  super
26
29
  AbstractController::Caching.eager_load!
30
+ AbstractController::Base.descendants.each do |controller|
31
+ unless controller.abstract?
32
+ controller.eager_load!
33
+ end
34
+ end
27
35
  end
28
36
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # :markup: markdown
4
+
3
5
  module ActionController
4
6
  module ApiRendering
5
7
  extend ActiveSupport::Concern
@@ -1,105 +1,108 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # :markup: markdown
4
+
3
5
  require "action_view"
4
6
  require "action_controller"
5
7
  require "action_controller/log_subscriber"
6
8
 
7
9
  module ActionController
8
- # API Controller is a lightweight version of ActionController::Base,
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,
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+.
10
+ # # Action Controller API
11
+ #
12
+ # API Controller is a lightweight version of ActionController::Base, created for
13
+ # applications that don't require all functionalities that a complete Rails
14
+ # controller provides, allowing you to create controllers with just the features
15
+ # that you need for API only applications.
16
+ #
17
+ # An API Controller is different from a normal controller in the sense that by
18
+ # default it doesn't include a number of features that are usually required by
19
+ # browser access only: layouts and templates rendering, flash, assets, and so
20
+ # on. This makes the entire controller stack thinner, suitable for API
21
+ # applications. It doesn't mean you won't have such features if you need them:
22
+ # they're all available for you to include in your application, they're just not
23
+ # part of the default API controller stack.
24
+ #
25
+ # Normally, `ApplicationController` is the only controller that inherits from
26
+ # `ActionController::API`. All other controllers in turn inherit from
27
+ # `ApplicationController`.
24
28
  #
25
29
  # A sample controller could look like this:
26
30
  #
27
- # class PostsController < ApplicationController
28
- # def index
29
- # posts = Post.all
30
- # render json: posts
31
+ # class PostsController < ApplicationController
32
+ # def index
33
+ # posts = Post.all
34
+ # render json: posts
35
+ # end
31
36
  # end
32
- # end
33
37
  #
34
38
  # Request, response, and parameters objects all work the exact same way as
35
39
  # ActionController::Base.
36
40
  #
37
- # == Renders
41
+ # ## Renders
38
42
  #
39
- # The default API Controller stack includes all renderers, which means you
40
- # can use <tt>render :json</tt> and siblings 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 <tt>204 No Content</tt>.
43
+ # The default API Controller stack includes all renderers, which means you can
44
+ # use `render :json` and siblings freely in your controllers. Keep in mind that
45
+ # templates are not going to be rendered, so you need to ensure your controller
46
+ # is calling either `render` or `redirect_to` in all actions, otherwise it will
47
+ # return `204 No Content`.
44
48
  #
45
- # def show
46
- # post = Post.find(params[:id])
47
- # render json: post
48
- # end
49
+ # def show
50
+ # post = Post.find(params[:id])
51
+ # render json: post
52
+ # end
49
53
  #
50
- # == Redirects
54
+ # ## Redirects
51
55
  #
52
56
  # 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
57
+ # `redirect_to` method in your controllers in the same way as in
54
58
  # ActionController::Base. For example:
55
59
  #
56
- # def create
57
- # redirect_to root_url and return if not_authorized?
58
- # # do stuff here
59
- # end
60
+ # def create
61
+ # redirect_to root_url and return if not_authorized?
62
+ # # do stuff here
63
+ # end
60
64
  #
61
- # == Adding New Behavior
65
+ # ## Adding New Behavior
62
66
  #
63
67
  # In some scenarios you may want to add back some functionality provided by
64
68
  # ActionController::Base 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 }
69
+ # `ActionController::API`, for instance `MimeResponds`. This module gives you
70
+ # the `respond_to` method. Adding it is quite simple, you just need to include
71
+ # the module in a specific controller or in `ApplicationController` in case you
72
+ # want it available in your entire application:
73
+ #
74
+ # class ApplicationController < ActionController::API
75
+ # include ActionController::MimeResponds
76
+ # end
77
+ #
78
+ # class PostsController < ApplicationController
79
+ # def index
80
+ # posts = Post.all
81
+ #
82
+ # respond_to do |format|
83
+ # format.json { render json: posts }
84
+ # format.xml { render xml: posts }
85
+ # end
82
86
  # end
83
87
  # end
84
- # end
85
88
  #
86
- # Make sure to check the modules included in ActionController::Base
87
- # if you want to use any other functionality that is not provided
88
- # by <tt>ActionController::API</tt> out of the box.
89
+ # Make sure to check the modules included in ActionController::Base if you want
90
+ # to use any other functionality that is not provided by `ActionController::API`
91
+ # out of the box.
89
92
  class API < Metal
90
93
  abstract!
91
94
 
92
- # Shortcut helper that returns all the ActionController::API modules except
93
- # the ones passed as arguments:
95
+ # Shortcut helper that returns all the ActionController::API modules except the
96
+ # ones passed as arguments:
94
97
  #
95
- # class MyAPIBaseController < ActionController::Metal
96
- # ActionController::API.without_modules(:UrlFor).each do |left|
97
- # include left
98
+ # class MyAPIBaseController < ActionController::Metal
99
+ # ActionController::API.without_modules(:UrlFor).each do |left|
100
+ # include left
101
+ # end
98
102
  # end
99
- # end
100
103
  #
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
104
+ # This gives better control over what you want to exclude and makes it easier to
105
+ # create an API controller class, instead of listing the modules required
103
106
  # manually.
104
107
  def self.without_modules(*modules)
105
108
  modules = modules.map do |m|
@@ -119,24 +122,26 @@ module ActionController
119
122
  ConditionalGet,
120
123
  BasicImplicitRender,
121
124
  StrongParameters,
125
+ RateLimiting,
126
+ Caching,
122
127
 
123
128
  DataStreaming,
124
129
  DefaultHeaders,
125
130
  Logging,
126
131
 
127
- # Before callbacks should also be executed as early as possible, so
128
- # also include them at the bottom.
132
+ # Before callbacks should also be executed as early as possible, so also include
133
+ # them at the bottom.
129
134
  AbstractController::Callbacks,
130
135
 
131
136
  # Append rescue at the bottom to wrap as much as possible.
132
137
  Rescue,
133
138
 
134
- # Add instrumentations hooks at the bottom, to ensure they instrument
135
- # all the methods properly.
139
+ # Add instrumentations hooks at the bottom, to ensure they instrument all the
140
+ # methods properly.
136
141
  Instrumentation,
137
142
 
138
- # Params wrapper should come before instrumentation so they are
139
- # properly showed in logs
143
+ # Params wrapper should come before instrumentation so they are properly showed
144
+ # in logs
140
145
  ParamsWrapper
141
146
  ]
142
147