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,13 +1,12 @@
|
|
1
|
-
require 'active_support/core_ext/class/attribute'
|
2
1
|
require 'active_support/core_ext/hash/slice'
|
3
2
|
require 'active_support/core_ext/hash/except'
|
4
|
-
require 'active_support/core_ext/array/wrap'
|
5
3
|
require 'active_support/core_ext/module/anonymous'
|
6
|
-
require '
|
4
|
+
require 'active_support/core_ext/struct'
|
5
|
+
require 'action_dispatch/http/mime_type'
|
7
6
|
|
8
7
|
module ActionController
|
9
|
-
# Wraps the parameters hash into a nested hash. This will allow clients to
|
10
|
-
#
|
8
|
+
# Wraps the parameters hash into a nested hash. This will allow clients to
|
9
|
+
# submit requests without having to specify any root elements.
|
11
10
|
#
|
12
11
|
# This functionality is enabled in +config/initializers/wrap_parameters.rb+
|
13
12
|
# and can be customized. If you are upgrading to \Rails 3.1, this file will
|
@@ -17,7 +16,7 @@ module ActionController
|
|
17
16
|
# a non-empty array:
|
18
17
|
#
|
19
18
|
# class UsersController < ApplicationController
|
20
|
-
# wrap_parameters :
|
19
|
+
# wrap_parameters format: [:json, :xml, :url_encoded_form, :multipart_form]
|
21
20
|
# end
|
22
21
|
#
|
23
22
|
# If you enable +ParamsWrapper+ for +:json+ format, instead of having to
|
@@ -40,16 +39,15 @@ module ActionController
|
|
40
39
|
# +:exclude+ options like this:
|
41
40
|
#
|
42
41
|
# class UsersController < ApplicationController
|
43
|
-
# wrap_parameters :person, :
|
42
|
+
# wrap_parameters :person, include: [:username, :password]
|
44
43
|
# end
|
45
44
|
#
|
46
|
-
# On ActiveRecord models with no +:include+ or +:exclude+ option set,
|
47
|
-
#
|
48
|
-
#
|
49
|
-
# method attribute_names.
|
45
|
+
# On ActiveRecord models with no +:include+ or +:exclude+ option set,
|
46
|
+
# it will only wrap the parameters returned by the class method
|
47
|
+
# <tt>attribute_names</tt>.
|
50
48
|
#
|
51
49
|
# If you're going to pass the parameters to an +ActiveModel+ object (such as
|
52
|
-
#
|
50
|
+
# <tt>User.new(params[:user])</tt>), you might consider passing the model class to
|
53
51
|
# the method instead. The +ParamsWrapper+ will actually try to determine the
|
54
52
|
# list of attribute names from the model and only wrap those attributes:
|
55
53
|
#
|
@@ -67,7 +65,7 @@ module ActionController
|
|
67
65
|
# class Admin::UsersController < ApplicationController
|
68
66
|
# end
|
69
67
|
#
|
70
|
-
# will try to check if
|
68
|
+
# will try to check if <tt>Admin::User</tt> or +User+ model exists, and use it to
|
71
69
|
# determine the wrapper key respectively. If both models don't exist,
|
72
70
|
# it will then fallback to use +user+ as the key.
|
73
71
|
module ParamsWrapper
|
@@ -75,17 +73,104 @@ module ActionController
|
|
75
73
|
|
76
74
|
EXCLUDE_PARAMETERS = %w(authenticity_token _method utf8)
|
77
75
|
|
76
|
+
require 'mutex_m'
|
77
|
+
|
78
|
+
class Options < Struct.new(:name, :format, :include, :exclude, :klass, :model) # :nodoc:
|
79
|
+
include Mutex_m
|
80
|
+
|
81
|
+
def self.from_hash(hash)
|
82
|
+
name = hash[:name]
|
83
|
+
format = Array(hash[:format])
|
84
|
+
include = hash[:include] && Array(hash[:include]).collect(&:to_s)
|
85
|
+
exclude = hash[:exclude] && Array(hash[:exclude]).collect(&:to_s)
|
86
|
+
new name, format, include, exclude, nil, nil
|
87
|
+
end
|
88
|
+
|
89
|
+
def initialize(name, format, include, exclude, klass, model) # nodoc
|
90
|
+
super
|
91
|
+
@include_set = include
|
92
|
+
@name_set = name
|
93
|
+
end
|
94
|
+
|
95
|
+
def model
|
96
|
+
super || synchronize { super || self.model = _default_wrap_model }
|
97
|
+
end
|
98
|
+
|
99
|
+
def include
|
100
|
+
return super if @include_set
|
101
|
+
|
102
|
+
m = model
|
103
|
+
synchronize do
|
104
|
+
return super if @include_set
|
105
|
+
|
106
|
+
@include_set = true
|
107
|
+
|
108
|
+
unless super || exclude
|
109
|
+
if m.respond_to?(:attribute_names) && m.attribute_names.any?
|
110
|
+
self.include = m.attribute_names
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def name
|
117
|
+
return super if @name_set
|
118
|
+
|
119
|
+
m = model
|
120
|
+
synchronize do
|
121
|
+
return super if @name_set
|
122
|
+
|
123
|
+
@name_set = true
|
124
|
+
|
125
|
+
unless super || klass.anonymous?
|
126
|
+
self.name = m ? m.to_s.demodulize.underscore :
|
127
|
+
klass.controller_name.singularize
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
private
|
133
|
+
# Determine the wrapper model from the controller's name. By convention,
|
134
|
+
# this could be done by trying to find the defined model that has the
|
135
|
+
# same singularize name as the controller. For example, +UsersController+
|
136
|
+
# will try to find if the +User+ model exists.
|
137
|
+
#
|
138
|
+
# This method also does namespace lookup. Foo::Bar::UsersController will
|
139
|
+
# try to find Foo::Bar::User, Foo::User and finally User.
|
140
|
+
def _default_wrap_model #:nodoc:
|
141
|
+
return nil if klass.anonymous?
|
142
|
+
model_name = klass.name.sub(/Controller$/, '').classify
|
143
|
+
|
144
|
+
begin
|
145
|
+
if model_klass = model_name.safe_constantize
|
146
|
+
model_klass
|
147
|
+
else
|
148
|
+
namespaces = model_name.split("::")
|
149
|
+
namespaces.delete_at(-2)
|
150
|
+
break if namespaces.last == model_name
|
151
|
+
model_name = namespaces.join("::")
|
152
|
+
end
|
153
|
+
end until model_klass
|
154
|
+
|
155
|
+
model_klass
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
78
159
|
included do
|
79
160
|
class_attribute :_wrapper_options
|
80
|
-
self._wrapper_options =
|
161
|
+
self._wrapper_options = Options.from_hash(format: [])
|
81
162
|
end
|
82
163
|
|
83
164
|
module ClassMethods
|
165
|
+
def _set_wrapper_options(options)
|
166
|
+
self._wrapper_options = Options.from_hash(options)
|
167
|
+
end
|
168
|
+
|
84
169
|
# Sets the name of the wrapper key, or the model which +ParamsWrapper+
|
85
170
|
# would use to determine the attribute names from.
|
86
171
|
#
|
87
172
|
# ==== Examples
|
88
|
-
# wrap_parameters :
|
173
|
+
# wrap_parameters format: :xml
|
89
174
|
# # enables the parameter wrapper for XML format
|
90
175
|
#
|
91
176
|
# wrap_parameters :person
|
@@ -95,7 +180,7 @@ module ActionController
|
|
95
180
|
# # wraps parameters by determining the wrapper key from Person class
|
96
181
|
# (+person+, in this case) and the list of attribute names
|
97
182
|
#
|
98
|
-
# wrap_parameters :
|
183
|
+
# wrap_parameters include: [:username, :title]
|
99
184
|
# # wraps only +:username+ and +:title+ attributes from parameters.
|
100
185
|
#
|
101
186
|
# wrap_parameters false
|
@@ -122,78 +207,36 @@ module ActionController
|
|
122
207
|
model = name_or_model_or_options
|
123
208
|
end
|
124
209
|
|
125
|
-
|
210
|
+
opts = Options.from_hash _wrapper_options.to_h.slice(:format).merge(options)
|
211
|
+
opts.model = model
|
212
|
+
opts.klass = self
|
213
|
+
|
214
|
+
self._wrapper_options = opts
|
126
215
|
end
|
127
216
|
|
128
217
|
# Sets the default wrapper key or model which will be used to determine
|
129
218
|
# wrapper key and attribute names. Will be called automatically when the
|
130
219
|
# module is inherited.
|
131
220
|
def inherited(klass)
|
132
|
-
if klass._wrapper_options
|
133
|
-
klass.
|
221
|
+
if klass._wrapper_options.format.any?
|
222
|
+
params = klass._wrapper_options.dup
|
223
|
+
params.klass = klass
|
224
|
+
klass._wrapper_options = params
|
134
225
|
end
|
135
226
|
super
|
136
227
|
end
|
137
|
-
|
138
|
-
protected
|
139
|
-
|
140
|
-
# Determine the wrapper model from the controller's name. By convention,
|
141
|
-
# this could be done by trying to find the defined model that has the
|
142
|
-
# same singularize name as the controller. For example, +UsersController+
|
143
|
-
# will try to find if the +User+ model exists.
|
144
|
-
#
|
145
|
-
# This method also does namespace lookup. Foo::Bar::UsersController will
|
146
|
-
# try to find Foo::Bar::User, Foo::User and finally User.
|
147
|
-
def _default_wrap_model #:nodoc:
|
148
|
-
return nil if self.anonymous?
|
149
|
-
model_name = self.name.sub(/Controller$/, '').classify
|
150
|
-
|
151
|
-
begin
|
152
|
-
if model_klass = model_name.safe_constantize
|
153
|
-
model_klass
|
154
|
-
else
|
155
|
-
namespaces = model_name.split("::")
|
156
|
-
namespaces.delete_at(-2)
|
157
|
-
break if namespaces.last == model_name
|
158
|
-
model_name = namespaces.join("::")
|
159
|
-
end
|
160
|
-
end until model_klass
|
161
|
-
|
162
|
-
model_klass
|
163
|
-
end
|
164
|
-
|
165
|
-
def _set_wrapper_defaults(options, model=nil)
|
166
|
-
options = options.dup
|
167
|
-
|
168
|
-
unless options[:include] || options[:exclude]
|
169
|
-
model ||= _default_wrap_model
|
170
|
-
role = options.has_key?(:as) ? options[:as] : :default
|
171
|
-
if model.respond_to?(:accessible_attributes) && model.accessible_attributes(role).present?
|
172
|
-
options[:include] = model.accessible_attributes(role).to_a
|
173
|
-
elsif model.respond_to?(:attribute_names) && model.attribute_names.present?
|
174
|
-
options[:include] = model.attribute_names
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
unless options[:name] || self.anonymous?
|
179
|
-
model ||= _default_wrap_model
|
180
|
-
options[:name] = model ? model.to_s.demodulize.underscore :
|
181
|
-
controller_name.singularize
|
182
|
-
end
|
183
|
-
|
184
|
-
options[:include] = Array.wrap(options[:include]).collect(&:to_s) if options[:include]
|
185
|
-
options[:exclude] = Array.wrap(options[:exclude]).collect(&:to_s) if options[:exclude]
|
186
|
-
options[:format] = Array.wrap(options[:format])
|
187
|
-
|
188
|
-
self._wrapper_options = options
|
189
|
-
end
|
190
228
|
end
|
191
229
|
|
192
230
|
# Performs parameters wrapping upon the request. Will be called automatically
|
193
231
|
# by the metal call stack.
|
194
232
|
def process_action(*args)
|
195
233
|
if _wrapper_enabled?
|
196
|
-
|
234
|
+
if request.parameters[_wrapper_key].present?
|
235
|
+
wrapped_hash = _extract_parameters(request.parameters)
|
236
|
+
else
|
237
|
+
wrapped_hash = _wrap_parameters request.request_parameters
|
238
|
+
end
|
239
|
+
|
197
240
|
wrapped_keys = request.request_parameters.keys
|
198
241
|
wrapped_filtered_hash = _wrap_parameters request.filtered_parameters.slice(*wrapped_keys)
|
199
242
|
|
@@ -201,7 +244,7 @@ module ActionController
|
|
201
244
|
request.parameters.merge! wrapped_hash
|
202
245
|
request.request_parameters.merge! wrapped_hash
|
203
246
|
|
204
|
-
# This will
|
247
|
+
# This will display the wrapped hash in the log file
|
205
248
|
request.filtered_parameters.merge! wrapped_filtered_hash
|
206
249
|
end
|
207
250
|
super
|
@@ -209,26 +252,28 @@ module ActionController
|
|
209
252
|
|
210
253
|
private
|
211
254
|
|
212
|
-
# Returns the wrapper key which will
|
255
|
+
# Returns the wrapper key which will be used to stored wrapped parameters.
|
213
256
|
def _wrapper_key
|
214
|
-
_wrapper_options
|
257
|
+
_wrapper_options.name
|
215
258
|
end
|
216
259
|
|
217
260
|
# Returns the list of enabled formats.
|
218
261
|
def _wrapper_formats
|
219
|
-
_wrapper_options
|
262
|
+
_wrapper_options.format
|
220
263
|
end
|
221
264
|
|
222
265
|
# Returns the list of parameters which will be selected for wrapped.
|
223
266
|
def _wrap_parameters(parameters)
|
224
|
-
|
267
|
+
{ _wrapper_key => _extract_parameters(parameters) }
|
268
|
+
end
|
269
|
+
|
270
|
+
def _extract_parameters(parameters)
|
271
|
+
if include_only = _wrapper_options.include
|
225
272
|
parameters.slice(*include_only)
|
226
273
|
else
|
227
|
-
exclude = _wrapper_options
|
274
|
+
exclude = _wrapper_options.exclude || []
|
228
275
|
parameters.except(*(exclude + EXCLUDE_PARAMETERS))
|
229
276
|
end
|
230
|
-
|
231
|
-
{ _wrapper_key => value }
|
232
277
|
end
|
233
278
|
|
234
279
|
# Checks if we should perform parameters wrapping.
|
@@ -6,11 +6,10 @@ module ActionController
|
|
6
6
|
extend ActiveSupport::Concern
|
7
7
|
|
8
8
|
delegate :headers, :status=, :location=, :content_type=,
|
9
|
-
:status, :location, :content_type, :to => "@_response"
|
9
|
+
:status, :location, :content_type, :response_code, :to => "@_response"
|
10
10
|
|
11
|
-
def dispatch(action, request
|
12
|
-
|
13
|
-
@_response.request ||= request
|
11
|
+
def dispatch(action, request)
|
12
|
+
set_response!(request)
|
14
13
|
super(action, request)
|
15
14
|
end
|
16
15
|
|
@@ -22,5 +21,12 @@ module ActionController
|
|
22
21
|
def reset_session
|
23
22
|
@_request.reset_session
|
24
23
|
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def set_response!(request)
|
28
|
+
@_response = ActionDispatch::Response.new
|
29
|
+
@_response.request = request
|
30
|
+
end
|
25
31
|
end
|
26
32
|
end
|
@@ -14,7 +14,7 @@ module ActionController
|
|
14
14
|
include ActionController::RackDelegation
|
15
15
|
include ActionController::UrlFor
|
16
16
|
|
17
|
-
# Redirects the browser to the target specified in +options+. This parameter can
|
17
|
+
# Redirects the browser to the target specified in +options+. This parameter can be any one of:
|
18
18
|
#
|
19
19
|
# * <tt>Hash</tt> - The URL will be generated by calling url_for with the +options+.
|
20
20
|
# * <tt>Record</tt> - The URL will be generated by calling url_for with the +options+, which will reference a named URL for that record.
|
@@ -24,8 +24,9 @@ module ActionController
|
|
24
24
|
# * <tt>:back</tt> - Back to the page that issued the request. Useful for forms that are triggered from multiple places.
|
25
25
|
# Short-hand for <tt>redirect_to(request.env["HTTP_REFERER"])</tt>
|
26
26
|
#
|
27
|
-
# Examples:
|
28
|
-
#
|
27
|
+
# === Examples:
|
28
|
+
#
|
29
|
+
# redirect_to action: "show", id: 5
|
29
30
|
# redirect_to post
|
30
31
|
# redirect_to "http://www.rubyonrails.org"
|
31
32
|
# redirect_to "/images/screenshot.jpg"
|
@@ -33,13 +34,12 @@ module ActionController
|
|
33
34
|
# redirect_to :back
|
34
35
|
# redirect_to proc { edit_post_url(@post) }
|
35
36
|
#
|
36
|
-
# The redirection happens as a "302
|
37
|
+
# The redirection happens as a "302 Found" header unless otherwise specified using the <tt>:status</tt> option:
|
37
38
|
#
|
38
|
-
#
|
39
|
-
# redirect_to
|
40
|
-
# redirect_to
|
41
|
-
# redirect_to
|
42
|
-
# redirect_to :action=>'atom', :status => 302
|
39
|
+
# redirect_to post_url(@post), status: :found
|
40
|
+
# redirect_to action: 'atom', status: :moved_permanently
|
41
|
+
# redirect_to post_url(@post), status: 301
|
42
|
+
# redirect_to action: 'atom', status: 302
|
43
43
|
#
|
44
44
|
# The status code can either be a standard {HTTP Status code}[http://www.iana.org/assignments/http-status-codes] as an
|
45
45
|
# integer, or a symbol representing the downcased, underscored and symbolized description.
|
@@ -51,29 +51,52 @@ module ActionController
|
|
51
51
|
# around this you can return a <tt>303 See Other</tt> status code which will be
|
52
52
|
# followed using a GET request.
|
53
53
|
#
|
54
|
-
#
|
55
|
-
# redirect_to
|
56
|
-
# redirect_to :action => 'index', :status => 303
|
54
|
+
# redirect_to posts_url, status: :see_other
|
55
|
+
# redirect_to action: 'index', status: 303
|
57
56
|
#
|
58
57
|
# It is also possible to assign a flash message as part of the redirection. There are two special accessors for the commonly used flash names
|
59
58
|
# +alert+ and +notice+ as well as a general purpose +flash+ bucket.
|
60
59
|
#
|
61
|
-
#
|
62
|
-
# redirect_to post_url(@post), :
|
63
|
-
# redirect_to post_url(@post), :
|
64
|
-
# redirect_to
|
65
|
-
# redirect_to { :action=>'atom' }, :alert => "Something serious happened"
|
60
|
+
# redirect_to post_url(@post), alert: "Watch it, mister!"
|
61
|
+
# redirect_to post_url(@post), status: :found, notice: "Pay attention to the road"
|
62
|
+
# redirect_to post_url(@post), status: 301, flash: { updated_post_id: @post.id }
|
63
|
+
# redirect_to({ action: 'atom' }, alert: "Something serious happened")
|
66
64
|
#
|
67
|
-
# When using <tt>redirect_to :back</tt>, if there is no referrer,
|
68
|
-
#
|
65
|
+
# When using <tt>redirect_to :back</tt>, if there is no referrer,
|
66
|
+
# <tt>ActionController::RedirectBackError</tt> will be raised. You
|
67
|
+
# may specify some fallback behavior for this case by rescuing
|
68
|
+
# <tt>ActionController::RedirectBackError</tt>.
|
69
69
|
def redirect_to(options = {}, response_status = {}) #:doc:
|
70
70
|
raise ActionControllerError.new("Cannot redirect to nil!") unless options
|
71
|
+
raise ActionControllerError.new("Cannot redirect to a parameter hash!") if options.is_a?(ActionController::Parameters)
|
71
72
|
raise AbstractController::DoubleRenderError if response_body
|
72
73
|
|
73
74
|
self.status = _extract_redirect_to_status(options, response_status)
|
74
|
-
self.location = _compute_redirect_to_location(options)
|
75
|
-
self.response_body = "<html><body>You are being <a href=\"#{ERB::Util.
|
75
|
+
self.location = _compute_redirect_to_location(request, options)
|
76
|
+
self.response_body = "<html><body>You are being <a href=\"#{ERB::Util.unwrapped_html_escape(location)}\">redirected</a>.</body></html>"
|
77
|
+
end
|
78
|
+
|
79
|
+
def _compute_redirect_to_location(request, options) #:nodoc:
|
80
|
+
case options
|
81
|
+
# The scheme name consist of a letter followed by any combination of
|
82
|
+
# letters, digits, and the plus ("+"), period ("."), or hyphen ("-")
|
83
|
+
# characters; and is terminated by a colon (":").
|
84
|
+
# See http://tools.ietf.org/html/rfc3986#section-3.1
|
85
|
+
# The protocol relative scheme starts with a double slash "//".
|
86
|
+
when /\A([a-z][a-z\d\-+\.]*:|\/\/).*/i
|
87
|
+
options
|
88
|
+
when String
|
89
|
+
request.protocol + request.host_with_port + options
|
90
|
+
when :back
|
91
|
+
request.headers["Referer"] or raise RedirectBackError
|
92
|
+
when Proc
|
93
|
+
_compute_redirect_to_location request, options.call
|
94
|
+
else
|
95
|
+
url_for(options)
|
96
|
+
end.delete("\0\r\n")
|
76
97
|
end
|
98
|
+
module_function :_compute_redirect_to_location
|
99
|
+
public :_compute_redirect_to_location
|
77
100
|
|
78
101
|
private
|
79
102
|
def _extract_redirect_to_status(options, response_status)
|
@@ -85,25 +108,5 @@ module ActionController
|
|
85
108
|
302
|
86
109
|
end
|
87
110
|
end
|
88
|
-
|
89
|
-
def _compute_redirect_to_location(options)
|
90
|
-
case options
|
91
|
-
# The scheme name consist of a letter followed by any combination of
|
92
|
-
# letters, digits, and the plus ("+"), period ("."), or hyphen ("-")
|
93
|
-
# characters; and is terminated by a colon (":").
|
94
|
-
# The protocol relative scheme starts with a double slash "//"
|
95
|
-
when %r{^(\w[\w+.-]*:|//).*}
|
96
|
-
options
|
97
|
-
when String
|
98
|
-
request.protocol + request.host_with_port + options
|
99
|
-
when :back
|
100
|
-
raise RedirectBackError unless refer = request.headers["Referer"]
|
101
|
-
refer
|
102
|
-
when Proc
|
103
|
-
_compute_redirect_to_location options.call
|
104
|
-
else
|
105
|
-
url_for(options)
|
106
|
-
end.gsub(/[\0\r\n]/, '')
|
107
|
-
end
|
108
111
|
end
|
109
112
|
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'active_support/core_ext/class/attribute'
|
2
|
-
require 'active_support/core_ext/object/blank'
|
3
1
|
require 'set'
|
4
2
|
|
5
3
|
module ActionController
|
@@ -8,6 +6,17 @@ module ActionController
|
|
8
6
|
Renderers.add(key, &block)
|
9
7
|
end
|
10
8
|
|
9
|
+
# See <tt>Renderers.remove</tt>
|
10
|
+
def self.remove_renderer(key)
|
11
|
+
Renderers.remove(key)
|
12
|
+
end
|
13
|
+
|
14
|
+
class MissingRenderer < LoadError
|
15
|
+
def initialize(format)
|
16
|
+
super "No renderer defined for format: #{format}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
11
20
|
module Renderers
|
12
21
|
extend ActiveSupport::Concern
|
13
22
|
|
@@ -25,23 +34,28 @@ module ActionController
|
|
25
34
|
end
|
26
35
|
|
27
36
|
def render_to_body(options)
|
28
|
-
|
37
|
+
_render_to_body_with_renderer(options) || super
|
29
38
|
end
|
30
39
|
|
31
|
-
def
|
40
|
+
def _render_to_body_with_renderer(options)
|
32
41
|
_renderers.each do |name|
|
33
42
|
if options.key?(name)
|
34
43
|
_process_options(options)
|
35
|
-
|
44
|
+
method_name = Renderers._render_with_renderer_method_name(name)
|
45
|
+
return send(method_name, options.delete(name), options)
|
36
46
|
end
|
37
47
|
end
|
38
48
|
nil
|
39
49
|
end
|
40
50
|
|
41
|
-
#
|
42
|
-
# Default
|
51
|
+
# A Set containing renderer names that correspond to available renderer procs.
|
52
|
+
# Default values are <tt>:json</tt>, <tt>:js</tt>, <tt>:xml</tt>.
|
43
53
|
RENDERERS = Set.new
|
44
54
|
|
55
|
+
def self._render_with_renderer_method_name(key)
|
56
|
+
"_render_with_renderer_#{key}"
|
57
|
+
end
|
58
|
+
|
45
59
|
# Adds a new renderer to call within controller actions.
|
46
60
|
# A renderer is invoked by passing its name as an option to
|
47
61
|
# <tt>AbstractController::Rendering#render</tt>. To create a renderer
|
@@ -49,14 +63,13 @@ module ActionController
|
|
49
63
|
# is the value paired with its key and the second is the remaining
|
50
64
|
# hash of options passed to +render+.
|
51
65
|
#
|
52
|
-
# === Example
|
53
66
|
# Create a csv renderer:
|
54
67
|
#
|
55
68
|
# ActionController::Renderers.add :csv do |obj, options|
|
56
69
|
# filename = options[:filename] || 'data'
|
57
70
|
# str = obj.respond_to?(:to_csv) ? obj.to_csv : obj.to_s
|
58
|
-
# send_data str, :
|
59
|
-
# :
|
71
|
+
# send_data str, type: Mime::CSV,
|
72
|
+
# disposition: "attachment; filename=#{filename}.csv"
|
60
73
|
# end
|
61
74
|
#
|
62
75
|
# Note that we used Mime::CSV for the csv mime type as it comes with Rails.
|
@@ -69,17 +82,25 @@ module ActionController
|
|
69
82
|
# @csvable = Csvable.find(params[:id])
|
70
83
|
# respond_to do |format|
|
71
84
|
# format.html
|
72
|
-
# format.csv { render :
|
73
|
-
#
|
85
|
+
# format.csv { render csv: @csvable, filename: @csvable.name }
|
86
|
+
# end
|
74
87
|
# end
|
75
|
-
# To use renderers and their mime types in more concise ways, see
|
76
|
-
# <tt>ActionController::MimeResponds::ClassMethods.respond_to</tt> and
|
77
|
-
# <tt>ActionController::MimeResponds#respond_with</tt>
|
78
88
|
def self.add(key, &block)
|
79
|
-
define_method(
|
89
|
+
define_method(_render_with_renderer_method_name(key), &block)
|
80
90
|
RENDERERS << key.to_sym
|
81
91
|
end
|
82
92
|
|
93
|
+
# This method is the opposite of add method.
|
94
|
+
#
|
95
|
+
# Usage:
|
96
|
+
#
|
97
|
+
# ActionController::Renderers.remove(:csv)
|
98
|
+
def self.remove(key)
|
99
|
+
RENDERERS.delete(key.to_sym)
|
100
|
+
method_name = _render_with_renderer_method_name(key)
|
101
|
+
remove_method(method_name) if method_defined?(method_name)
|
102
|
+
end
|
103
|
+
|
83
104
|
module All
|
84
105
|
extend ActiveSupport::Concern
|
85
106
|
include Renderers
|
@@ -91,9 +112,17 @@ module ActionController
|
|
91
112
|
|
92
113
|
add :json do |json, options|
|
93
114
|
json = json.to_json(options) unless json.kind_of?(String)
|
94
|
-
|
95
|
-
|
96
|
-
|
115
|
+
|
116
|
+
if options[:callback].present?
|
117
|
+
if content_type.nil? || content_type == Mime::JSON
|
118
|
+
self.content_type = Mime::JS
|
119
|
+
end
|
120
|
+
|
121
|
+
"/**/#{options[:callback]}(#{json})"
|
122
|
+
else
|
123
|
+
self.content_type ||= Mime::JSON
|
124
|
+
json
|
125
|
+
end
|
97
126
|
end
|
98
127
|
|
99
128
|
add :js do |js, options|
|