actionpack 7.0.8.1 → 7.2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +94 -500
- data/MIT-LICENSE +1 -1
- data/README.rdoc +2 -2
- data/lib/abstract_controller/asset_paths.rb +2 -0
- data/lib/abstract_controller/base.rb +119 -106
- data/lib/abstract_controller/caching/fragments.rb +51 -52
- data/lib/abstract_controller/caching.rb +2 -0
- data/lib/abstract_controller/callbacks.rb +94 -67
- data/lib/abstract_controller/collector.rb +6 -6
- data/lib/abstract_controller/deprecator.rb +9 -0
- data/lib/abstract_controller/error.rb +2 -0
- data/lib/abstract_controller/helpers.rb +121 -91
- data/lib/abstract_controller/logger.rb +2 -0
- data/lib/abstract_controller/railties/routes_helpers.rb +3 -16
- data/lib/abstract_controller/rendering.rb +14 -13
- data/lib/abstract_controller/translation.rb +12 -30
- data/lib/abstract_controller/url_for.rb +9 -5
- data/lib/abstract_controller.rb +8 -0
- data/lib/action_controller/api/api_rendering.rb +2 -0
- data/lib/action_controller/api.rb +78 -73
- data/lib/action_controller/base.rb +199 -141
- data/lib/action_controller/caching.rb +16 -11
- data/lib/action_controller/deprecator.rb +9 -0
- data/lib/action_controller/form_builder.rb +21 -16
- data/lib/action_controller/log_subscriber.rb +19 -5
- data/lib/action_controller/metal/allow_browser.rb +123 -0
- data/lib/action_controller/metal/basic_implicit_render.rb +2 -0
- data/lib/action_controller/metal/conditional_get.rb +187 -174
- data/lib/action_controller/metal/content_security_policy.rb +26 -25
- data/lib/action_controller/metal/cookies.rb +4 -2
- data/lib/action_controller/metal/data_streaming.rb +65 -54
- data/lib/action_controller/metal/default_headers.rb +6 -2
- data/lib/action_controller/metal/etag_with_flash.rb +4 -0
- data/lib/action_controller/metal/etag_with_template_digest.rb +18 -14
- data/lib/action_controller/metal/exceptions.rb +19 -9
- data/lib/action_controller/metal/flash.rb +12 -10
- data/lib/action_controller/metal/head.rb +20 -16
- data/lib/action_controller/metal/helpers.rb +64 -67
- data/lib/action_controller/metal/http_authentication.rb +214 -200
- data/lib/action_controller/metal/implicit_render.rb +21 -17
- data/lib/action_controller/metal/instrumentation.rb +22 -12
- data/lib/action_controller/metal/live.rb +125 -92
- data/lib/action_controller/metal/logging.rb +6 -4
- data/lib/action_controller/metal/mime_responds.rb +151 -142
- data/lib/action_controller/metal/parameter_encoding.rb +34 -32
- data/lib/action_controller/metal/params_wrapper.rb +58 -58
- data/lib/action_controller/metal/permissions_policy.rb +14 -13
- data/lib/action_controller/metal/rate_limiting.rb +62 -0
- data/lib/action_controller/metal/redirecting.rb +110 -84
- data/lib/action_controller/metal/renderers.rb +50 -49
- data/lib/action_controller/metal/rendering.rb +103 -82
- data/lib/action_controller/metal/request_forgery_protection.rb +279 -161
- data/lib/action_controller/metal/rescue.rb +12 -8
- data/lib/action_controller/metal/streaming.rb +174 -132
- data/lib/action_controller/metal/strong_parameters.rb +598 -473
- data/lib/action_controller/metal/testing.rb +2 -0
- data/lib/action_controller/metal/url_for.rb +23 -14
- data/lib/action_controller/metal.rb +145 -61
- data/lib/action_controller/railtie.rb +25 -9
- data/lib/action_controller/railties/helpers.rb +2 -0
- data/lib/action_controller/renderer.rb +105 -66
- data/lib/action_controller/template_assertions.rb +4 -2
- data/lib/action_controller/test_case.rb +157 -128
- data/lib/action_controller.rb +17 -3
- data/lib/action_dispatch/constants.rb +34 -0
- data/lib/action_dispatch/deprecator.rb +9 -0
- data/lib/action_dispatch/http/cache.rb +28 -29
- data/lib/action_dispatch/http/content_disposition.rb +2 -0
- data/lib/action_dispatch/http/content_security_policy.rb +69 -49
- data/lib/action_dispatch/http/filter_parameters.rb +27 -12
- data/lib/action_dispatch/http/filter_redirect.rb +22 -1
- data/lib/action_dispatch/http/headers.rb +23 -21
- data/lib/action_dispatch/http/mime_negotiation.rb +37 -48
- data/lib/action_dispatch/http/mime_type.rb +60 -30
- data/lib/action_dispatch/http/mime_types.rb +5 -1
- data/lib/action_dispatch/http/parameters.rb +12 -10
- data/lib/action_dispatch/http/permissions_policy.rb +32 -34
- data/lib/action_dispatch/http/rack_cache.rb +4 -0
- data/lib/action_dispatch/http/request.rb +132 -79
- data/lib/action_dispatch/http/response.rb +136 -103
- data/lib/action_dispatch/http/upload.rb +19 -15
- data/lib/action_dispatch/http/url.rb +75 -73
- data/lib/action_dispatch/journey/formatter.rb +19 -6
- data/lib/action_dispatch/journey/gtg/builder.rb +4 -3
- data/lib/action_dispatch/journey/gtg/simulator.rb +2 -0
- data/lib/action_dispatch/journey/gtg/transition_table.rb +10 -8
- data/lib/action_dispatch/journey/nfa/dot.rb +2 -0
- data/lib/action_dispatch/journey/nodes/node.rb +6 -5
- data/lib/action_dispatch/journey/parser.rb +4 -3
- data/lib/action_dispatch/journey/parser_extras.rb +2 -0
- data/lib/action_dispatch/journey/path/pattern.rb +18 -15
- data/lib/action_dispatch/journey/route.rb +12 -9
- data/lib/action_dispatch/journey/router/utils.rb +16 -15
- data/lib/action_dispatch/journey/router.rb +13 -10
- data/lib/action_dispatch/journey/routes.rb +6 -4
- data/lib/action_dispatch/journey/scanner.rb +4 -2
- data/lib/action_dispatch/journey/visitors.rb +2 -0
- data/lib/action_dispatch/journey.rb +2 -0
- data/lib/action_dispatch/log_subscriber.rb +25 -0
- data/lib/action_dispatch/middleware/actionable_exceptions.rb +7 -6
- data/lib/action_dispatch/middleware/assume_ssl.rb +27 -0
- data/lib/action_dispatch/middleware/callbacks.rb +4 -0
- data/lib/action_dispatch/middleware/cookies.rb +192 -194
- data/lib/action_dispatch/middleware/debug_exceptions.rb +36 -27
- data/lib/action_dispatch/middleware/debug_locks.rb +18 -13
- data/lib/action_dispatch/middleware/debug_view.rb +9 -2
- data/lib/action_dispatch/middleware/exception_wrapper.rb +181 -27
- data/lib/action_dispatch/middleware/executor.rb +9 -1
- data/lib/action_dispatch/middleware/flash.rb +65 -46
- data/lib/action_dispatch/middleware/host_authorization.rb +22 -17
- data/lib/action_dispatch/middleware/public_exceptions.rb +12 -8
- data/lib/action_dispatch/middleware/reloader.rb +9 -5
- data/lib/action_dispatch/middleware/remote_ip.rb +88 -83
- data/lib/action_dispatch/middleware/request_id.rb +15 -8
- data/lib/action_dispatch/middleware/server_timing.rb +8 -6
- data/lib/action_dispatch/middleware/session/abstract_store.rb +7 -0
- data/lib/action_dispatch/middleware/session/cache_store.rb +14 -7
- data/lib/action_dispatch/middleware/session/cookie_store.rb +32 -25
- data/lib/action_dispatch/middleware/session/mem_cache_store.rb +9 -3
- data/lib/action_dispatch/middleware/show_exceptions.rb +42 -28
- data/lib/action_dispatch/middleware/ssl.rb +60 -45
- data/lib/action_dispatch/middleware/stack.rb +15 -9
- data/lib/action_dispatch/middleware/static.rb +40 -34
- data/lib/action_dispatch/middleware/templates/rescues/_actions.html.erb +2 -2
- data/lib/action_dispatch/middleware/templates/rescues/_message_and_suggestions.html.erb +4 -4
- data/lib/action_dispatch/middleware/templates/rescues/_source.html.erb +8 -1
- data/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb +7 -7
- data/lib/action_dispatch/middleware/templates/rescues/diagnostics.text.erb +2 -2
- data/lib/action_dispatch/middleware/templates/rescues/layout.erb +17 -0
- data/lib/action_dispatch/middleware/templates/rescues/missing_exact_template.html.erb +16 -12
- data/lib/action_dispatch/middleware/templates/rescues/missing_template.html.erb +1 -1
- data/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb +3 -3
- data/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb +4 -4
- data/lib/action_dispatch/middleware/templates/rescues/unknown_action.html.erb +1 -1
- data/lib/action_dispatch/middleware/templates/rescues/unknown_action.text.erb +1 -1
- data/lib/action_dispatch/middleware/templates/routes/_route.html.erb +3 -0
- data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +47 -38
- data/lib/action_dispatch/railtie.rb +12 -4
- data/lib/action_dispatch/request/session.rb +39 -27
- data/lib/action_dispatch/request/utils.rb +10 -3
- data/lib/action_dispatch/routing/endpoint.rb +2 -0
- data/lib/action_dispatch/routing/inspector.rb +59 -9
- data/lib/action_dispatch/routing/mapper.rb +686 -639
- data/lib/action_dispatch/routing/polymorphic_routes.rb +70 -61
- data/lib/action_dispatch/routing/redirection.rb +52 -38
- data/lib/action_dispatch/routing/route_set.rb +106 -62
- data/lib/action_dispatch/routing/routes_proxy.rb +16 -19
- data/lib/action_dispatch/routing/url_for.rb +131 -122
- data/lib/action_dispatch/routing.rb +152 -150
- data/lib/action_dispatch/system_test_case.rb +91 -81
- data/lib/action_dispatch/system_testing/browser.rb +27 -19
- data/lib/action_dispatch/system_testing/driver.rb +16 -22
- data/lib/action_dispatch/system_testing/server.rb +2 -0
- data/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb +53 -31
- data/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb +2 -0
- data/lib/action_dispatch/testing/assertion_response.rb +9 -7
- data/lib/action_dispatch/testing/assertions/response.rb +36 -26
- data/lib/action_dispatch/testing/assertions/routing.rb +203 -95
- data/lib/action_dispatch/testing/assertions.rb +5 -1
- data/lib/action_dispatch/testing/integration.rb +240 -229
- data/lib/action_dispatch/testing/request_encoder.rb +6 -1
- data/lib/action_dispatch/testing/test_helpers/page_dump_helper.rb +35 -0
- data/lib/action_dispatch/testing/test_process.rb +14 -9
- data/lib/action_dispatch/testing/test_request.rb +4 -2
- data/lib/action_dispatch/testing/test_response.rb +34 -19
- data/lib/action_dispatch.rb +52 -21
- data/lib/action_pack/gem_version.rb +5 -3
- data/lib/action_pack/version.rb +3 -1
- data/lib/action_pack.rb +18 -17
- metadata +91 -32
@@ -1,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(...)
|
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
|
24
|
+
# sticks the result in `self.response_body`.
|
23
25
|
#
|
24
|
-
# Supported options depend on the underlying
|
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
|
40
|
+
# instead of setting `self.response_body`.
|
39
41
|
#
|
40
|
-
# If a component extends the semantics of
|
41
|
-
# extends it to be anything that responds to the method each), this method
|
42
|
-
#
|
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
|
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
|
-
#
|
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
|
71
|
-
#
|
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
|
-
|
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
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
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
|
-
|
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
|
-
|
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
|
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
|
-
#
|
5
|
-
#
|
6
|
-
#
|
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
|
9
|
-
#
|
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
|
data/lib/abstract_controller.rb
CHANGED
@@ -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,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
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
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
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
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
|
-
#
|
41
|
+
# ## Renders
|
38
42
|
#
|
39
|
-
# The default API Controller stack includes all renderers, which means you
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
43
|
-
#
|
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
|
-
#
|
46
|
-
#
|
47
|
-
#
|
48
|
-
#
|
49
|
+
# def show
|
50
|
+
# post = Post.find(params[:id])
|
51
|
+
# render json: post
|
52
|
+
# end
|
49
53
|
#
|
50
|
-
#
|
54
|
+
# ## Redirects
|
51
55
|
#
|
52
56
|
# Redirects are used to move from one action to another. You can use the
|
53
|
-
#
|
57
|
+
# `redirect_to` method in your controllers in the same way as in
|
54
58
|
# ActionController::Base. For example:
|
55
59
|
#
|
56
|
-
#
|
57
|
-
#
|
58
|
-
#
|
59
|
-
#
|
60
|
+
# def create
|
61
|
+
# redirect_to root_url and return if not_authorized?
|
62
|
+
# # do stuff here
|
63
|
+
# end
|
60
64
|
#
|
61
|
-
#
|
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
|
-
#
|
66
|
-
#
|
67
|
-
#
|
68
|
-
#
|
69
|
-
#
|
70
|
-
#
|
71
|
-
#
|
72
|
-
#
|
73
|
-
#
|
74
|
-
#
|
75
|
-
#
|
76
|
-
#
|
77
|
-
#
|
78
|
-
#
|
79
|
-
#
|
80
|
-
#
|
81
|
-
#
|
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
|
-
#
|
88
|
-
#
|
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
|
-
#
|
95
|
+
# Shortcut helper that returns all the ActionController::API modules except the
|
96
|
+
# ones passed as arguments:
|
94
97
|
#
|
95
|
-
#
|
96
|
-
#
|
97
|
-
#
|
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
|
-
#
|
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
|
-
#
|
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
|
-
#
|
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
|
-
#
|
143
|
+
# Params wrapper should come before instrumentation so they are properly showed
|
144
|
+
# in logs
|
140
145
|
ParamsWrapper
|
141
146
|
]
|
142
147
|
|