actionpack 3.2.19 → 4.2.11.3
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of actionpack might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/CHANGELOG.md +412 -503
- data/MIT-LICENSE +1 -1
- data/README.rdoc +11 -294
- data/lib/abstract_controller/asset_paths.rb +2 -2
- data/lib/abstract_controller/base.rb +52 -18
- data/lib/abstract_controller/callbacks.rb +87 -89
- data/lib/abstract_controller/collector.rb +17 -3
- data/lib/abstract_controller/helpers.rb +41 -14
- data/lib/abstract_controller/logger.rb +1 -2
- data/lib/abstract_controller/railties/routes_helpers.rb +3 -3
- data/lib/abstract_controller/rendering.rb +65 -118
- data/lib/abstract_controller/translation.rb +16 -1
- data/lib/abstract_controller/url_for.rb +7 -7
- data/lib/abstract_controller.rb +2 -10
- data/lib/action_controller/base.rb +61 -28
- data/lib/action_controller/caching/fragments.rb +30 -54
- data/lib/action_controller/caching.rb +38 -35
- data/lib/action_controller/log_subscriber.rb +35 -18
- data/lib/action_controller/metal/conditional_get.rb +103 -34
- data/lib/action_controller/metal/data_streaming.rb +20 -26
- data/lib/action_controller/metal/etag_with_template_digest.rb +50 -0
- data/lib/action_controller/metal/exceptions.rb +19 -6
- data/lib/action_controller/metal/flash.rb +41 -9
- data/lib/action_controller/metal/force_ssl.rb +70 -12
- data/lib/action_controller/metal/head.rb +30 -7
- data/lib/action_controller/metal/helpers.rb +11 -11
- data/lib/action_controller/metal/hide_actions.rb +0 -1
- data/lib/action_controller/metal/http_authentication.rb +140 -94
- data/lib/action_controller/metal/implicit_render.rb +1 -1
- data/lib/action_controller/metal/instrumentation.rb +11 -7
- data/lib/action_controller/metal/live.rb +328 -0
- data/lib/action_controller/metal/mime_responds.rb +161 -152
- data/lib/action_controller/metal/params_wrapper.rb +126 -81
- data/lib/action_controller/metal/rack_delegation.rb +10 -4
- data/lib/action_controller/metal/redirecting.rb +44 -41
- data/lib/action_controller/metal/renderers.rb +48 -19
- data/lib/action_controller/metal/rendering.rb +46 -11
- data/lib/action_controller/metal/request_forgery_protection.rb +250 -29
- data/lib/action_controller/metal/streaming.rb +30 -38
- data/lib/action_controller/metal/strong_parameters.rb +669 -0
- data/lib/action_controller/metal/testing.rb +12 -18
- data/lib/action_controller/metal/url_for.rb +31 -29
- data/lib/action_controller/metal.rb +31 -40
- data/lib/action_controller/model_naming.rb +12 -0
- data/lib/action_controller/railtie.rb +38 -18
- data/lib/action_controller/railties/helpers.rb +22 -0
- data/lib/action_controller/test_case.rb +359 -173
- data/lib/action_controller.rb +9 -16
- data/lib/action_dispatch/http/cache.rb +64 -11
- data/lib/action_dispatch/http/filter_parameters.rb +20 -10
- data/lib/action_dispatch/http/filter_redirect.rb +38 -0
- data/lib/action_dispatch/http/headers.rb +85 -17
- data/lib/action_dispatch/http/mime_negotiation.rb +55 -5
- data/lib/action_dispatch/http/mime_type.rb +167 -114
- data/lib/action_dispatch/http/mime_types.rb +2 -1
- data/lib/action_dispatch/http/parameter_filter.rb +44 -46
- data/lib/action_dispatch/http/parameters.rb +30 -46
- data/lib/action_dispatch/http/rack_cache.rb +2 -3
- data/lib/action_dispatch/http/request.rb +108 -45
- data/lib/action_dispatch/http/response.rb +247 -48
- data/lib/action_dispatch/http/upload.rb +60 -29
- data/lib/action_dispatch/http/url.rb +135 -45
- data/lib/action_dispatch/journey/backwards.rb +5 -0
- data/lib/action_dispatch/journey/formatter.rb +166 -0
- data/lib/action_dispatch/journey/gtg/builder.rb +162 -0
- data/lib/action_dispatch/journey/gtg/simulator.rb +47 -0
- data/lib/action_dispatch/journey/gtg/transition_table.rb +157 -0
- data/lib/action_dispatch/journey/nfa/builder.rb +76 -0
- data/lib/action_dispatch/journey/nfa/dot.rb +36 -0
- data/lib/action_dispatch/journey/nfa/simulator.rb +47 -0
- data/lib/action_dispatch/journey/nfa/transition_table.rb +163 -0
- data/lib/action_dispatch/journey/nodes/node.rb +128 -0
- data/lib/action_dispatch/journey/parser.rb +198 -0
- data/lib/action_dispatch/journey/parser.y +49 -0
- data/lib/action_dispatch/journey/parser_extras.rb +23 -0
- data/lib/action_dispatch/journey/path/pattern.rb +193 -0
- data/lib/action_dispatch/journey/route.rb +125 -0
- data/lib/action_dispatch/journey/router/strexp.rb +27 -0
- data/lib/action_dispatch/journey/router/utils.rb +93 -0
- data/lib/action_dispatch/journey/router.rb +144 -0
- data/lib/action_dispatch/journey/routes.rb +80 -0
- data/lib/action_dispatch/journey/scanner.rb +61 -0
- data/lib/action_dispatch/journey/visitors.rb +221 -0
- data/lib/action_dispatch/journey/visualizer/fsm.css +30 -0
- data/lib/action_dispatch/journey/visualizer/fsm.js +134 -0
- data/lib/action_dispatch/journey/visualizer/index.html.erb +52 -0
- data/lib/action_dispatch/journey.rb +5 -0
- data/lib/action_dispatch/middleware/callbacks.rb +16 -11
- data/lib/action_dispatch/middleware/cookies.rb +346 -125
- data/lib/action_dispatch/middleware/debug_exceptions.rb +52 -24
- data/lib/action_dispatch/middleware/exception_wrapper.rb +75 -9
- data/lib/action_dispatch/middleware/flash.rb +85 -72
- data/lib/action_dispatch/middleware/params_parser.rb +16 -31
- data/lib/action_dispatch/middleware/public_exceptions.rb +39 -14
- data/lib/action_dispatch/middleware/reloader.rb +16 -7
- data/lib/action_dispatch/middleware/remote_ip.rb +132 -40
- data/lib/action_dispatch/middleware/request_id.rb +3 -7
- data/lib/action_dispatch/middleware/session/abstract_store.rb +22 -20
- data/lib/action_dispatch/middleware/session/cache_store.rb +3 -3
- data/lib/action_dispatch/middleware/session/cookie_store.rb +84 -29
- data/lib/action_dispatch/middleware/session/mem_cache_store.rb +8 -3
- data/lib/action_dispatch/middleware/show_exceptions.rb +15 -44
- data/lib/action_dispatch/middleware/ssl.rb +72 -0
- data/lib/action_dispatch/middleware/stack.rb +6 -1
- data/lib/action_dispatch/middleware/static.rb +80 -23
- data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb +34 -0
- data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.text.erb +23 -0
- data/lib/action_dispatch/middleware/templates/rescues/_source.erb +27 -0
- data/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb +52 -0
- data/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb +9 -0
- data/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb +16 -0
- data/lib/action_dispatch/middleware/templates/rescues/diagnostics.text.erb +9 -0
- data/lib/action_dispatch/middleware/templates/rescues/layout.erb +133 -5
- data/lib/action_dispatch/middleware/templates/rescues/missing_template.html.erb +11 -0
- data/lib/action_dispatch/middleware/templates/rescues/missing_template.text.erb +3 -0
- data/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb +32 -0
- data/lib/action_dispatch/middleware/templates/rescues/routing_error.text.erb +11 -0
- data/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb +20 -0
- data/lib/action_dispatch/middleware/templates/rescues/template_error.text.erb +7 -0
- data/lib/action_dispatch/middleware/templates/rescues/unknown_action.html.erb +6 -0
- data/lib/action_dispatch/middleware/templates/rescues/unknown_action.text.erb +3 -0
- data/lib/action_dispatch/middleware/templates/routes/_route.html.erb +16 -0
- data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +200 -0
- data/lib/action_dispatch/railtie.rb +19 -6
- data/lib/action_dispatch/request/session.rb +193 -0
- data/lib/action_dispatch/request/utils.rb +35 -0
- data/lib/action_dispatch/routing/endpoint.rb +10 -0
- data/lib/action_dispatch/routing/inspector.rb +234 -0
- data/lib/action_dispatch/routing/mapper.rb +897 -436
- data/lib/action_dispatch/routing/polymorphic_routes.rb +213 -92
- data/lib/action_dispatch/routing/redirection.rb +97 -37
- data/lib/action_dispatch/routing/route_set.rb +432 -239
- data/lib/action_dispatch/routing/routes_proxy.rb +7 -4
- data/lib/action_dispatch/routing/url_for.rb +63 -34
- data/lib/action_dispatch/routing.rb +57 -89
- data/lib/action_dispatch/testing/assertions/dom.rb +2 -36
- data/lib/action_dispatch/testing/assertions/response.rb +24 -38
- data/lib/action_dispatch/testing/assertions/routing.rb +55 -54
- data/lib/action_dispatch/testing/assertions/selector.rb +2 -434
- data/lib/action_dispatch/testing/assertions/tag.rb +2 -137
- data/lib/action_dispatch/testing/assertions.rb +11 -7
- data/lib/action_dispatch/testing/integration.rb +88 -72
- data/lib/action_dispatch/testing/test_process.rb +9 -6
- data/lib/action_dispatch/testing/test_request.rb +13 -9
- data/lib/action_dispatch/testing/test_response.rb +1 -5
- data/lib/action_dispatch.rb +24 -21
- data/lib/action_pack/gem_version.rb +15 -0
- data/lib/action_pack/version.rb +5 -7
- data/lib/action_pack.rb +1 -1
- metadata +181 -292
- data/lib/abstract_controller/layouts.rb +0 -423
- data/lib/abstract_controller/view_paths.rb +0 -96
- data/lib/action_controller/caching/actions.rb +0 -185
- data/lib/action_controller/caching/pages.rb +0 -187
- data/lib/action_controller/caching/sweeping.rb +0 -97
- data/lib/action_controller/deprecated/integration_test.rb +0 -2
- data/lib/action_controller/deprecated/performance_test.rb +0 -1
- data/lib/action_controller/deprecated.rb +0 -3
- data/lib/action_controller/metal/compatibility.rb +0 -65
- data/lib/action_controller/metal/responder.rb +0 -286
- data/lib/action_controller/metal/session_management.rb +0 -14
- data/lib/action_controller/railties/paths.rb +0 -25
- data/lib/action_controller/record_identifier.rb +0 -85
- data/lib/action_controller/vendor/html-scanner/html/document.rb +0 -68
- data/lib/action_controller/vendor/html-scanner/html/node.rb +0 -532
- data/lib/action_controller/vendor/html-scanner/html/sanitizer.rb +0 -177
- data/lib/action_controller/vendor/html-scanner/html/selector.rb +0 -830
- data/lib/action_controller/vendor/html-scanner/html/tokenizer.rb +0 -107
- data/lib/action_controller/vendor/html-scanner/html/version.rb +0 -11
- data/lib/action_controller/vendor/html-scanner.rb +0 -20
- data/lib/action_dispatch/middleware/best_standards_support.rb +0 -30
- data/lib/action_dispatch/middleware/body_proxy.rb +0 -30
- data/lib/action_dispatch/middleware/head.rb +0 -18
- data/lib/action_dispatch/middleware/rescue.rb +0 -26
- data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb +0 -31
- data/lib/action_dispatch/middleware/templates/rescues/_trace.erb +0 -26
- data/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb +0 -10
- data/lib/action_dispatch/middleware/templates/rescues/missing_template.erb +0 -2
- data/lib/action_dispatch/middleware/templates/rescues/routing_error.erb +0 -15
- data/lib/action_dispatch/middleware/templates/rescues/template_error.erb +0 -17
- data/lib/action_dispatch/middleware/templates/rescues/unknown_action.erb +0 -2
- data/lib/action_dispatch/testing/performance_test.rb +0 -10
- data/lib/action_view/asset_paths.rb +0 -142
- data/lib/action_view/base.rb +0 -220
- data/lib/action_view/buffers.rb +0 -43
- data/lib/action_view/context.rb +0 -36
- data/lib/action_view/flows.rb +0 -79
- data/lib/action_view/helpers/active_model_helper.rb +0 -50
- data/lib/action_view/helpers/asset_paths.rb +0 -7
- data/lib/action_view/helpers/asset_tag_helper.rb +0 -457
- data/lib/action_view/helpers/asset_tag_helpers/asset_include_tag.rb +0 -146
- data/lib/action_view/helpers/asset_tag_helpers/asset_paths.rb +0 -93
- data/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb +0 -193
- data/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb +0 -148
- data/lib/action_view/helpers/atom_feed_helper.rb +0 -200
- data/lib/action_view/helpers/cache_helper.rb +0 -64
- data/lib/action_view/helpers/capture_helper.rb +0 -203
- data/lib/action_view/helpers/controller_helper.rb +0 -25
- data/lib/action_view/helpers/csrf_helper.rb +0 -32
- data/lib/action_view/helpers/date_helper.rb +0 -1062
- data/lib/action_view/helpers/debug_helper.rb +0 -40
- data/lib/action_view/helpers/form_helper.rb +0 -1486
- data/lib/action_view/helpers/form_options_helper.rb +0 -658
- data/lib/action_view/helpers/form_tag_helper.rb +0 -685
- data/lib/action_view/helpers/javascript_helper.rb +0 -110
- data/lib/action_view/helpers/number_helper.rb +0 -622
- data/lib/action_view/helpers/output_safety_helper.rb +0 -38
- data/lib/action_view/helpers/record_tag_helper.rb +0 -111
- data/lib/action_view/helpers/rendering_helper.rb +0 -90
- data/lib/action_view/helpers/sanitize_helper.rb +0 -259
- data/lib/action_view/helpers/tag_helper.rb +0 -160
- data/lib/action_view/helpers/text_helper.rb +0 -426
- data/lib/action_view/helpers/translation_helper.rb +0 -91
- data/lib/action_view/helpers/url_helper.rb +0 -693
- data/lib/action_view/helpers.rb +0 -60
- data/lib/action_view/locale/en.yml +0 -160
- data/lib/action_view/log_subscriber.rb +0 -28
- data/lib/action_view/lookup_context.rb +0 -254
- data/lib/action_view/path_set.rb +0 -89
- data/lib/action_view/railtie.rb +0 -55
- data/lib/action_view/renderer/abstract_renderer.rb +0 -41
- data/lib/action_view/renderer/partial_renderer.rb +0 -415
- data/lib/action_view/renderer/renderer.rb +0 -54
- data/lib/action_view/renderer/streaming_template_renderer.rb +0 -106
- data/lib/action_view/renderer/template_renderer.rb +0 -94
- data/lib/action_view/template/error.rb +0 -128
- data/lib/action_view/template/handlers/builder.rb +0 -26
- data/lib/action_view/template/handlers/erb.rb +0 -125
- data/lib/action_view/template/handlers.rb +0 -50
- data/lib/action_view/template/resolver.rb +0 -272
- data/lib/action_view/template/text.rb +0 -30
- data/lib/action_view/template.rb +0 -337
- data/lib/action_view/test_case.rb +0 -245
- data/lib/action_view/testing/resolvers.rb +0 -50
- data/lib/action_view.rb +0 -84
- data/lib/sprockets/assets.rake +0 -99
- data/lib/sprockets/bootstrap.rb +0 -37
- data/lib/sprockets/compressors.rb +0 -83
- data/lib/sprockets/helpers/isolated_helper.rb +0 -13
- data/lib/sprockets/helpers/rails_helper.rb +0 -182
- data/lib/sprockets/helpers.rb +0 -6
- data/lib/sprockets/railtie.rb +0 -62
- data/lib/sprockets/static_compiler.rb +0 -56
@@ -1,6 +1,8 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require 'active_support/concern'
|
2
|
+
require 'active_support/core_ext/class/attribute'
|
3
|
+
require 'action_view'
|
4
|
+
require 'action_view/view_paths'
|
5
|
+
require 'set'
|
4
6
|
|
5
7
|
module AbstractController
|
6
8
|
class DoubleRenderError < Error
|
@@ -11,169 +13,114 @@ module AbstractController
|
|
11
13
|
end
|
12
14
|
end
|
13
15
|
|
14
|
-
# This is a class to fix I18n global state. Whenever you provide I18n.locale during a request,
|
15
|
-
# it will trigger the lookup_context and consequently expire the cache.
|
16
|
-
class I18nProxy < ::I18n::Config #:nodoc:
|
17
|
-
attr_reader :original_config, :lookup_context
|
18
|
-
|
19
|
-
def initialize(original_config, lookup_context)
|
20
|
-
original_config = original_config.original_config if original_config.respond_to?(:original_config)
|
21
|
-
@original_config, @lookup_context = original_config, lookup_context
|
22
|
-
end
|
23
|
-
|
24
|
-
def locale
|
25
|
-
@original_config.locale
|
26
|
-
end
|
27
|
-
|
28
|
-
def locale=(value)
|
29
|
-
@lookup_context.locale = value
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
16
|
module Rendering
|
34
17
|
extend ActiveSupport::Concern
|
35
|
-
include
|
36
|
-
|
37
|
-
included do
|
38
|
-
class_attribute :protected_instance_variables
|
39
|
-
self.protected_instance_variables = []
|
40
|
-
end
|
41
|
-
|
42
|
-
# Overwrite process to setup I18n proxy.
|
43
|
-
def process(*) #:nodoc:
|
44
|
-
old_config, I18n.config = I18n.config, I18nProxy.new(I18n.config, lookup_context)
|
45
|
-
super
|
46
|
-
ensure
|
47
|
-
I18n.config = old_config
|
48
|
-
end
|
49
|
-
|
50
|
-
module ClassMethods
|
51
|
-
def view_context_class
|
52
|
-
@view_context_class ||= begin
|
53
|
-
routes = _routes if respond_to?(:_routes)
|
54
|
-
helpers = _helpers if respond_to?(:_helpers)
|
55
|
-
ActionView::Base.prepare(routes, helpers)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
attr_internal_writer :view_context_class
|
61
|
-
|
62
|
-
def view_context_class
|
63
|
-
@_view_context_class ||= self.class.view_context_class
|
64
|
-
end
|
65
|
-
|
66
|
-
# An instance of a view class. The default view class is ActionView::Base
|
67
|
-
#
|
68
|
-
# The view class must have the following methods:
|
69
|
-
# View.new[lookup_context, assigns, controller]
|
70
|
-
# Create a new ActionView instance for a controller
|
71
|
-
# View#render[options]
|
72
|
-
# Returns String with the rendered template
|
73
|
-
#
|
74
|
-
# Override this method in a module to change the default behavior.
|
75
|
-
def view_context
|
76
|
-
view_context_class.new(view_renderer, view_assigns, self)
|
77
|
-
end
|
78
|
-
|
79
|
-
# Returns an object that is able to render templates.
|
80
|
-
def view_renderer
|
81
|
-
@_view_renderer ||= ActionView::Renderer.new(lookup_context)
|
82
|
-
end
|
18
|
+
include ActionView::ViewPaths
|
83
19
|
|
84
20
|
# Normalize arguments, options and then delegates render_to_body and
|
85
21
|
# sticks the result in self.response_body.
|
22
|
+
# :api: public
|
86
23
|
def render(*args, &block)
|
87
24
|
options = _normalize_render(*args, &block)
|
88
25
|
self.response_body = render_to_body(options)
|
26
|
+
_process_format(rendered_format, options) if rendered_format
|
27
|
+
self.response_body
|
89
28
|
end
|
90
29
|
|
91
|
-
# Raw rendering of a template to a string.
|
92
|
-
#
|
30
|
+
# Raw rendering of a template to a string.
|
31
|
+
#
|
32
|
+
# It is similar to render, except that it does not
|
33
|
+
# set the response_body and it should be guaranteed
|
34
|
+
# to always return a string.
|
35
|
+
#
|
36
|
+
# If a component extends the semantics of response_body
|
37
|
+
# (as Action Controller extends it to be anything that
|
38
|
+
# responds to the method each), this method needs to be
|
39
|
+
# overridden in order to still return a string.
|
93
40
|
# :api: plugin
|
94
41
|
def render_to_string(*args, &block)
|
95
42
|
options = _normalize_render(*args, &block)
|
96
43
|
render_to_body(options)
|
97
44
|
end
|
98
45
|
|
99
|
-
#
|
100
|
-
# :api:
|
46
|
+
# Performs the actual template rendering.
|
47
|
+
# :api: public
|
101
48
|
def render_to_body(options = {})
|
102
|
-
_process_options(options)
|
103
|
-
_render_template(options)
|
104
49
|
end
|
105
50
|
|
106
|
-
#
|
107
|
-
# :api:
|
108
|
-
def
|
109
|
-
|
110
|
-
view_renderer.render(view_context, options)
|
51
|
+
# Returns Content-Type of rendered content
|
52
|
+
# :api: public
|
53
|
+
def rendered_format
|
54
|
+
Mime::TEXT
|
111
55
|
end
|
112
56
|
|
113
|
-
DEFAULT_PROTECTED_INSTANCE_VARIABLES = %w(
|
57
|
+
DEFAULT_PROTECTED_INSTANCE_VARIABLES = Set.new %w(
|
114
58
|
@_action_name @_response_body @_formats @_prefixes @_config
|
115
59
|
@_view_context_class @_view_renderer @_lookup_context
|
116
|
-
|
60
|
+
@_routes @_db_runtime
|
61
|
+
).map(&:to_sym)
|
117
62
|
|
118
63
|
# This method should return a hash with assigns.
|
119
64
|
# You can overwrite this configuration per controller.
|
120
65
|
# :api: public
|
121
66
|
def view_assigns
|
122
|
-
|
123
|
-
variables
|
124
|
-
variables -= protected_instance_variables
|
125
|
-
variables -= DEFAULT_PROTECTED_INSTANCE_VARIABLES
|
126
|
-
variables.each { |name| hash[name.to_s[1, name.length]] = instance_variable_get(name) }
|
127
|
-
hash
|
128
|
-
end
|
67
|
+
protected_vars = _protected_ivars
|
68
|
+
variables = instance_variables
|
129
69
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
def _normalize_render(*args, &block)
|
135
|
-
options = _normalize_args(*args, &block)
|
136
|
-
_normalize_options(options)
|
137
|
-
options
|
70
|
+
variables.reject! { |s| protected_vars.include? s }
|
71
|
+
variables.each_with_object({}) { |name, hash|
|
72
|
+
hash[name.slice(1, name.length)] = instance_variable_get(name)
|
73
|
+
}
|
138
74
|
end
|
139
75
|
|
140
76
|
# Normalize args by converting render "foo" to render :action => "foo" and
|
141
77
|
# render "foo/bar" to render :file => "foo/bar".
|
142
78
|
# :api: plugin
|
143
79
|
def _normalize_args(action=nil, options={})
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
80
|
+
if action.respond_to?(:permitted?)
|
81
|
+
if action.permitted?
|
82
|
+
action
|
83
|
+
else
|
84
|
+
raise ArgumentError, "render parameters are not permitted"
|
85
|
+
end
|
86
|
+
elsif action.is_a?(Hash)
|
87
|
+
action
|
152
88
|
else
|
153
|
-
options
|
89
|
+
options
|
154
90
|
end
|
155
|
-
|
156
|
-
options
|
157
91
|
end
|
158
92
|
|
159
93
|
# Normalize options.
|
160
94
|
# :api: plugin
|
161
95
|
def _normalize_options(options)
|
162
|
-
if options[:partial] == true
|
163
|
-
options[:partial] = action_name
|
164
|
-
end
|
165
|
-
|
166
|
-
if (options.keys & [:partial, :file, :template]).empty?
|
167
|
-
options[:prefixes] ||= _prefixes
|
168
|
-
end
|
169
|
-
|
170
|
-
options[:template] ||= (options[:action] || action_name).to_s
|
171
96
|
options
|
172
97
|
end
|
173
98
|
|
174
99
|
# Process extra options.
|
175
100
|
# :api: plugin
|
176
101
|
def _process_options(options)
|
102
|
+
options
|
103
|
+
end
|
104
|
+
|
105
|
+
# Process the rendered format.
|
106
|
+
# :api: private
|
107
|
+
def _process_format(format, options = {})
|
108
|
+
end
|
109
|
+
|
110
|
+
# Normalize args and options.
|
111
|
+
# :api: private
|
112
|
+
def _normalize_render(*args, &block)
|
113
|
+
options = _normalize_args(*args, &block)
|
114
|
+
#TODO: remove defined? when we restore AP <=> AV dependency
|
115
|
+
if defined?(request) && request && request.variant.present?
|
116
|
+
options[:variant] = request.variant
|
117
|
+
end
|
118
|
+
_normalize_options(options)
|
119
|
+
options
|
120
|
+
end
|
121
|
+
|
122
|
+
def _protected_ivars # :nodoc:
|
123
|
+
DEFAULT_PROTECTED_INSTANCE_VARIABLES
|
177
124
|
end
|
178
125
|
end
|
179
126
|
end
|
@@ -1,13 +1,28 @@
|
|
1
1
|
module AbstractController
|
2
2
|
module Translation
|
3
|
+
# Delegates to <tt>I18n.translate</tt>. Also aliased as <tt>t</tt>.
|
4
|
+
#
|
5
|
+
# When the given key starts with a period, it will be scoped by the current
|
6
|
+
# controller and action. So if you call <tt>translate(".foo")</tt> from
|
7
|
+
# <tt>PeopleController#index</tt>, it will convert the call to
|
8
|
+
# <tt>I18n.translate("people.index.foo")</tt>. This makes it less repetitive
|
9
|
+
# to translate many keys within the same controller / action and gives you a
|
10
|
+
# simple framework for scoping them consistently.
|
3
11
|
def translate(*args)
|
12
|
+
key = args.first
|
13
|
+
if key.is_a?(String) && (key[0] == '.')
|
14
|
+
key = "#{ controller_path.tr('/', '.') }.#{ action_name }#{ key }"
|
15
|
+
args[0] = key
|
16
|
+
end
|
17
|
+
|
4
18
|
I18n.translate(*args)
|
5
19
|
end
|
6
20
|
alias :t :translate
|
7
21
|
|
22
|
+
# Delegates to <tt>I18n.localize</tt>. Also aliased as <tt>l</tt>.
|
8
23
|
def localize(*args)
|
9
24
|
I18n.localize(*args)
|
10
25
|
end
|
11
26
|
alias :l :localize
|
12
27
|
end
|
13
|
-
end
|
28
|
+
end
|
@@ -1,17 +1,17 @@
|
|
1
|
-
# Includes +url_for+ into the host class (e.g. an abstract controller or mailer). The class
|
2
|
-
# has to provide a +RouteSet+ by implementing the <tt>_routes</tt> methods. Otherwise, an
|
3
|
-
# exception will be raised.
|
4
|
-
#
|
5
|
-
# Note that this module is completely decoupled from HTTP - the only requirement is a valid
|
6
|
-
# <tt>_routes</tt> implementation.
|
7
1
|
module AbstractController
|
2
|
+
# Includes +url_for+ into the host class (e.g. an abstract controller or mailer). The class
|
3
|
+
# has to provide a +RouteSet+ by implementing the <tt>_routes</tt> methods. Otherwise, an
|
4
|
+
# exception will be raised.
|
5
|
+
#
|
6
|
+
# Note that this module is completely decoupled from HTTP - the only requirement is a valid
|
7
|
+
# <tt>_routes</tt> implementation.
|
8
8
|
module UrlFor
|
9
9
|
extend ActiveSupport::Concern
|
10
10
|
include ActionDispatch::Routing::UrlFor
|
11
11
|
|
12
12
|
def _routes
|
13
13
|
raise "In order to use #url_for, you must include routing helpers explicitly. " \
|
14
|
-
"For instance, `include Rails.application.routes.url_helpers"
|
14
|
+
"For instance, `include Rails.application.routes.url_helpers`."
|
15
15
|
end
|
16
16
|
|
17
17
|
module ClassMethods
|
data/lib/abstract_controller.rb
CHANGED
@@ -1,13 +1,6 @@
|
|
1
|
-
activesupport_path = File.expand_path('../../../activesupport/lib', __FILE__)
|
2
|
-
$:.unshift(activesupport_path) if File.directory?(activesupport_path) && !$:.include?(activesupport_path)
|
3
|
-
|
4
1
|
require 'action_pack'
|
5
|
-
require 'active_support/
|
6
|
-
require 'active_support/ruby/shim'
|
7
|
-
require 'active_support/dependencies/autoload'
|
8
|
-
require 'active_support/core_ext/class/attribute'
|
2
|
+
require 'active_support/rails'
|
9
3
|
require 'active_support/core_ext/module/attr_internal'
|
10
|
-
require 'active_support/core_ext/module/delegation'
|
11
4
|
require 'active_support/core_ext/module/anonymous'
|
12
5
|
require 'active_support/i18n'
|
13
6
|
|
@@ -17,12 +10,11 @@ module AbstractController
|
|
17
10
|
autoload :Base
|
18
11
|
autoload :Callbacks
|
19
12
|
autoload :Collector
|
13
|
+
autoload :DoubleRenderError, "abstract_controller/rendering"
|
20
14
|
autoload :Helpers
|
21
|
-
autoload :Layouts
|
22
15
|
autoload :Logger
|
23
16
|
autoload :Rendering
|
24
17
|
autoload :Translation
|
25
18
|
autoload :AssetPaths
|
26
|
-
autoload :ViewPaths
|
27
19
|
autoload :UrlFor
|
28
20
|
end
|
@@ -1,8 +1,10 @@
|
|
1
|
+
require 'action_view'
|
1
2
|
require "action_controller/log_subscriber"
|
3
|
+
require "action_controller/metal/params_wrapper"
|
2
4
|
|
3
5
|
module ActionController
|
4
6
|
# Action Controllers are the core of a web request in \Rails. They are made up of one or more actions that are executed
|
5
|
-
# on request and then either
|
7
|
+
# on request and then either it renders a template or redirects to another action. An action is defined as a public method
|
6
8
|
# on the controller, which will automatically be made accessible to the web-server through \Rails Routes.
|
7
9
|
#
|
8
10
|
# By default, only the ApplicationController in a \Rails application inherits from <tt>ActionController::Base</tt>. All other
|
@@ -42,8 +44,8 @@ module ActionController
|
|
42
44
|
# The full request object is available via the request accessor and is primarily used to query for HTTP headers:
|
43
45
|
#
|
44
46
|
# def server_ip
|
45
|
-
# location = request.env["
|
46
|
-
# render :
|
47
|
+
# location = request.env["REMOTE_ADDR"]
|
48
|
+
# render plain: "This server hosted at #{location}"
|
47
49
|
# end
|
48
50
|
#
|
49
51
|
# == Parameters
|
@@ -58,7 +60,7 @@ module ActionController
|
|
58
60
|
# <input type="text" name="post[address]" value="hyacintvej">
|
59
61
|
#
|
60
62
|
# A request stemming from a form holding these inputs will include <tt>{ "post" => { "name" => "david", "address" => "hyacintvej" } }</tt>.
|
61
|
-
# If the address input had been named
|
63
|
+
# If the address input had been named <tt>post[address][street]</tt>, the params would have included
|
62
64
|
# <tt>{ "post" => { "address" => { "street" => "hyacintvej" } } }</tt>. There's no limit to the depth of the nesting.
|
63
65
|
#
|
64
66
|
# == Sessions
|
@@ -84,19 +86,10 @@ module ActionController
|
|
84
86
|
# or you can remove the entire session with +reset_session+.
|
85
87
|
#
|
86
88
|
# Sessions are stored by default in a browser cookie that's cryptographically signed, but unencrypted.
|
87
|
-
# This prevents the user from tampering with the session but also allows
|
89
|
+
# This prevents the user from tampering with the session but also allows them to see its contents.
|
88
90
|
#
|
89
91
|
# Do not put secret information in cookie-based sessions!
|
90
92
|
#
|
91
|
-
# Other options for session storage:
|
92
|
-
#
|
93
|
-
# * ActiveRecord::SessionStore - Sessions are stored in your database, which works better than PStore with multiple app servers and,
|
94
|
-
# unlike CookieStore, hides your session contents from the user. To use ActiveRecord::SessionStore, set
|
95
|
-
#
|
96
|
-
# MyApplication::Application.config.session_store :active_record_store
|
97
|
-
#
|
98
|
-
# in your <tt>config/initializers/session_store.rb</tt> and run <tt>script/rails g session_migration</tt>.
|
99
|
-
#
|
100
93
|
# == Responses
|
101
94
|
#
|
102
95
|
# Each action results in a response, which holds the headers and document to be sent to the user's browser. The actual response
|
@@ -116,15 +109,15 @@ module ActionController
|
|
116
109
|
#
|
117
110
|
# Title: <%= @post.title %>
|
118
111
|
#
|
119
|
-
# You don't have to rely on the automated rendering. For example, actions that could result in the rendering of different templates
|
112
|
+
# You don't have to rely on the automated rendering. For example, actions that could result in the rendering of different templates
|
120
113
|
# will use the manual rendering methods:
|
121
114
|
#
|
122
115
|
# def search
|
123
116
|
# @results = Search.find(params[:query])
|
124
117
|
# case @results.count
|
125
|
-
# when 0 then render :
|
126
|
-
# when 1 then render :
|
127
|
-
# when 2..10 then render :
|
118
|
+
# when 0 then render action: "no_results"
|
119
|
+
# when 1 then render action: "show"
|
120
|
+
# when 2..10 then render action: "show_many"
|
128
121
|
# end
|
129
122
|
# end
|
130
123
|
#
|
@@ -133,14 +126,14 @@ module ActionController
|
|
133
126
|
# == Redirects
|
134
127
|
#
|
135
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
|
136
|
-
# database, we might like to show the user the new entry. Because we're following good DRY principles (Don't Repeat Yourself), we're
|
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
|
137
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:
|
138
131
|
#
|
139
132
|
# def create
|
140
133
|
# @entry = Entry.new(params[:entry])
|
141
134
|
# if @entry.save
|
142
135
|
# # The entry was saved correctly, redirect to show
|
143
|
-
# redirect_to :
|
136
|
+
# redirect_to action: 'show', id: @entry.id
|
144
137
|
# else
|
145
138
|
# # things didn't go so well, do something else
|
146
139
|
# end
|
@@ -157,20 +150,48 @@ module ActionController
|
|
157
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:
|
158
151
|
#
|
159
152
|
# def do_something
|
160
|
-
# redirect_to :
|
161
|
-
# render :
|
153
|
+
# redirect_to action: "elsewhere"
|
154
|
+
# render action: "overthere" # raises DoubleRenderError
|
162
155
|
# end
|
163
156
|
#
|
164
157
|
# If you need to redirect on the condition of something, then be sure to add "and return" to halt execution.
|
165
158
|
#
|
166
159
|
# def do_something
|
167
|
-
# redirect_to(:
|
168
|
-
# render :
|
160
|
+
# redirect_to(action: "elsewhere") and return if monkeys.nil?
|
161
|
+
# render action: "overthere" # won't be called if monkeys is nil
|
169
162
|
# end
|
170
163
|
#
|
171
164
|
class Base < Metal
|
172
165
|
abstract!
|
173
166
|
|
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
|
+
# Shortcut helper that returns all the modules included in
|
184
|
+
# ActionController::Base except the ones passed as arguments:
|
185
|
+
#
|
186
|
+
# class MyBaseController < ActionController::Metal
|
187
|
+
# ActionController::Base.without_modules(:ParamsWrapper, :Streaming).each do |left|
|
188
|
+
# include left
|
189
|
+
# end
|
190
|
+
# end
|
191
|
+
#
|
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.
|
174
195
|
def self.without_modules(*modules)
|
175
196
|
modules = modules.map do |m|
|
176
197
|
m.is_a?(Symbol) ? ActionController.const_get(m) : m
|
@@ -180,7 +201,7 @@ module ActionController
|
|
180
201
|
end
|
181
202
|
|
182
203
|
MODULES = [
|
183
|
-
AbstractController::
|
204
|
+
AbstractController::Rendering,
|
184
205
|
AbstractController::Translation,
|
185
206
|
AbstractController::AssetPaths,
|
186
207
|
|
@@ -188,13 +209,16 @@ module ActionController
|
|
188
209
|
HideActions,
|
189
210
|
UrlFor,
|
190
211
|
Redirecting,
|
212
|
+
ActionView::Layouts,
|
191
213
|
Rendering,
|
192
214
|
Renderers::All,
|
193
215
|
ConditionalGet,
|
216
|
+
EtagWithTemplateDigest,
|
194
217
|
RackDelegation,
|
195
218
|
Caching,
|
196
219
|
MimeResponds,
|
197
220
|
ImplicitRender,
|
221
|
+
StrongParameters,
|
198
222
|
|
199
223
|
Cookies,
|
200
224
|
Flash,
|
@@ -202,7 +226,6 @@ module ActionController
|
|
202
226
|
ForceSSL,
|
203
227
|
Streaming,
|
204
228
|
DataStreaming,
|
205
|
-
RecordIdentifier,
|
206
229
|
HttpAuthentication::Basic::ControllerMethods,
|
207
230
|
HttpAuthentication::Digest::ControllerMethods,
|
208
231
|
HttpAuthentication::Token::ControllerMethods,
|
@@ -227,8 +250,18 @@ module ActionController
|
|
227
250
|
include mod
|
228
251
|
end
|
229
252
|
|
230
|
-
#
|
231
|
-
|
253
|
+
# 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
|
261
|
+
|
262
|
+
def self.protected_instance_variables
|
263
|
+
PROTECTED_IVARS
|
264
|
+
end
|
232
265
|
|
233
266
|
ActiveSupport.run_load_hooks(:action_controller, self)
|
234
267
|
end
|
@@ -1,59 +1,29 @@
|
|
1
|
-
module ActionController
|
1
|
+
module ActionController
|
2
2
|
module Caching
|
3
|
-
# Fragment caching is used for caching various blocks within
|
3
|
+
# Fragment caching is used for caching various blocks within
|
4
4
|
# views without caching the entire action as a whole. This is
|
5
|
-
# useful when certain elements of an action change frequently or
|
6
|
-
# depend on complicated state while other parts rarely change or
|
5
|
+
# useful when certain elements of an action change frequently or
|
6
|
+
# depend on complicated state while other parts rarely change or
|
7
7
|
# can be shared amongst multiple parties. The caching is done using
|
8
|
-
# the
|
9
|
-
#
|
8
|
+
# the +cache+ helper available in the Action View. See
|
9
|
+
# ActionView::Helpers::CacheHelper for more information.
|
10
10
|
#
|
11
|
-
#
|
11
|
+
# While it's strongly recommended that you use key-based cache
|
12
|
+
# expiration (see links in CacheHelper for more information),
|
13
|
+
# it is also possible to manually expire caches. For example:
|
12
14
|
#
|
13
|
-
#
|
14
|
-
# All the topics in the system:
|
15
|
-
# <%= render :partial => "topic", :collection => Topic.all %>
|
16
|
-
# <% end %>
|
17
|
-
#
|
18
|
-
# This cache will bind the name of the action that called it, so if
|
19
|
-
# this code was part of the view for the topics/list action, you
|
20
|
-
# would be able to invalidate it using:
|
21
|
-
#
|
22
|
-
# expire_fragment(:controller => "topics", :action => "list")
|
23
|
-
#
|
24
|
-
# This default behavior is limited if you need to cache multiple
|
25
|
-
# fragments per action or if the action itself is cached using
|
26
|
-
# <tt>caches_action</tt>. To remedy this, there is an option to
|
27
|
-
# qualify the name of the cached fragment by using the
|
28
|
-
# <tt>:action_suffix</tt> option:
|
29
|
-
#
|
30
|
-
# <% cache(:action => "list", :action_suffix => "all_topics") do %>
|
31
|
-
#
|
32
|
-
# That would result in a name such as
|
33
|
-
# <tt>/topics/list/all_topics</tt>, avoiding conflicts with the
|
34
|
-
# action cache and with any fragments that use a different suffix.
|
35
|
-
# Note that the URL doesn't have to really exist or be callable
|
36
|
-
# - the url_for system is just used to generate unique cache names
|
37
|
-
# that we can refer to when we need to expire the cache.
|
38
|
-
#
|
39
|
-
# The expiration call for this example is:
|
40
|
-
#
|
41
|
-
# expire_fragment(:controller => "topics",
|
42
|
-
# :action => "list",
|
43
|
-
# :action_suffix => "all_topics")
|
15
|
+
# expire_fragment('name_of_cache')
|
44
16
|
module Fragments
|
45
|
-
# Given a key (as described in
|
46
|
-
# a key suitable for use in reading, writing, or expiring a
|
47
|
-
# cached fragment.
|
48
|
-
# return value of url_for on that hash (without the protocol).
|
49
|
-
# All keys are prefixed with <tt>views/</tt> and uses
|
17
|
+
# Given a key (as described in +expire_fragment+), returns
|
18
|
+
# a key suitable for use in reading, writing, or expiring a
|
19
|
+
# cached fragment. All keys are prefixed with <tt>views/</tt> and uses
|
50
20
|
# ActiveSupport::Cache.expand_cache_key for the expansion.
|
51
21
|
def fragment_cache_key(key)
|
52
22
|
ActiveSupport::Cache.expand_cache_key(key.is_a?(Hash) ? url_for(key).split("://").last : key, :views)
|
53
23
|
end
|
54
24
|
|
55
|
-
# Writes
|
56
|
-
#
|
25
|
+
# Writes +content+ to the location signified by
|
26
|
+
# +key+ (see +expire_fragment+ for acceptable formats).
|
57
27
|
def write_fragment(key, content, options = nil)
|
58
28
|
return content unless cache_configured?
|
59
29
|
|
@@ -65,8 +35,8 @@ module ActionController #:nodoc:
|
|
65
35
|
content
|
66
36
|
end
|
67
37
|
|
68
|
-
# Reads a cached fragment from the location signified by
|
69
|
-
# (see
|
38
|
+
# Reads a cached fragment from the location signified by +key+
|
39
|
+
# (see +expire_fragment+ for acceptable formats).
|
70
40
|
def read_fragment(key, options = nil)
|
71
41
|
return unless cache_configured?
|
72
42
|
|
@@ -77,8 +47,8 @@ module ActionController #:nodoc:
|
|
77
47
|
end
|
78
48
|
end
|
79
49
|
|
80
|
-
# Check if a cached fragment from the location signified by
|
81
|
-
#
|
50
|
+
# Check if a cached fragment from the location signified by
|
51
|
+
# +key+ exists (see +expire_fragment+ for acceptable formats).
|
82
52
|
def fragment_exist?(key, options = nil)
|
83
53
|
return unless cache_configured?
|
84
54
|
key = fragment_cache_key(key)
|
@@ -95,7 +65,7 @@ module ActionController #:nodoc:
|
|
95
65
|
# * String - This would normally take the form of a path, like
|
96
66
|
# <tt>pages/45/notes</tt>.
|
97
67
|
# * Hash - Treated as an implicit call to +url_for+, like
|
98
|
-
# <tt>{:
|
68
|
+
# <tt>{ controller: 'pages', action: 'notes', id: 45}</tt>
|
99
69
|
# * Regexp - Will remove any fragment that matches, so
|
100
70
|
# <tt>%r{pages/\d*/notes}</tt> might remove all notes. Make sure you
|
101
71
|
# don't use anchors in the regex (<tt>^</tt> or <tt>$</tt>) because
|
@@ -104,8 +74,8 @@ module ActionController #:nodoc:
|
|
104
74
|
# only supported on caches that can iterate over all keys (unlike
|
105
75
|
# memcached).
|
106
76
|
#
|
107
|
-
# +options+ is passed through to the cache store's
|
108
|
-
# method (or <tt>delete_matched</tt>, for Regexp keys.
|
77
|
+
# +options+ is passed through to the cache store's +delete+
|
78
|
+
# method (or <tt>delete_matched</tt>, for Regexp keys).
|
109
79
|
def expire_fragment(key, options = nil)
|
110
80
|
return unless cache_configured?
|
111
81
|
key = fragment_cache_key(key) unless key.is_a?(Regexp)
|
@@ -119,8 +89,14 @@ module ActionController #:nodoc:
|
|
119
89
|
end
|
120
90
|
end
|
121
91
|
|
122
|
-
def instrument_fragment_cache(name, key)
|
123
|
-
|
92
|
+
def instrument_fragment_cache(name, key) # :nodoc:
|
93
|
+
payload = {
|
94
|
+
controller: controller_name,
|
95
|
+
action: action_name,
|
96
|
+
key: key
|
97
|
+
}
|
98
|
+
|
99
|
+
ActiveSupport::Notifications.instrument("#{name}.action_controller", payload) { yield }
|
124
100
|
end
|
125
101
|
end
|
126
102
|
end
|