actionpack 4.2.8 → 5.2.4.2
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 +5 -5
- data/CHANGELOG.md +285 -444
- data/MIT-LICENSE +1 -1
- data/README.rdoc +6 -7
- data/lib/abstract_controller.rb +12 -5
- data/lib/abstract_controller/asset_paths.rb +2 -0
- data/lib/abstract_controller/base.rb +45 -49
- data/lib/abstract_controller/caching.rb +66 -0
- data/lib/{action_controller → abstract_controller}/caching/fragments.rb +78 -15
- data/lib/abstract_controller/callbacks.rb +47 -31
- data/lib/abstract_controller/collector.rb +8 -11
- data/lib/abstract_controller/error.rb +6 -0
- data/lib/abstract_controller/helpers.rb +25 -25
- data/lib/abstract_controller/logger.rb +2 -0
- data/lib/abstract_controller/railties/routes_helpers.rb +4 -2
- data/lib/abstract_controller/rendering.rb +42 -41
- data/lib/abstract_controller/translation.rb +10 -7
- data/lib/abstract_controller/url_for.rb +2 -0
- data/lib/action_controller.rb +29 -21
- data/lib/action_controller/api.rb +149 -0
- data/lib/action_controller/api/api_rendering.rb +16 -0
- data/lib/action_controller/base.rb +27 -19
- data/lib/action_controller/caching.rb +14 -57
- data/lib/action_controller/form_builder.rb +50 -0
- data/lib/action_controller/log_subscriber.rb +10 -15
- data/lib/action_controller/metal.rb +98 -83
- data/lib/action_controller/metal/basic_implicit_render.rb +13 -0
- data/lib/action_controller/metal/conditional_get.rb +118 -44
- data/lib/action_controller/metal/content_security_policy.rb +52 -0
- data/lib/action_controller/metal/cookies.rb +3 -3
- data/lib/action_controller/metal/data_streaming.rb +27 -46
- data/lib/action_controller/metal/etag_with_flash.rb +18 -0
- data/lib/action_controller/metal/etag_with_template_digest.rb +20 -13
- data/lib/action_controller/metal/exceptions.rb +8 -14
- data/lib/action_controller/metal/flash.rb +4 -3
- data/lib/action_controller/metal/force_ssl.rb +23 -21
- data/lib/action_controller/metal/head.rb +21 -19
- data/lib/action_controller/metal/helpers.rb +24 -14
- data/lib/action_controller/metal/http_authentication.rb +64 -57
- data/lib/action_controller/metal/implicit_render.rb +62 -8
- data/lib/action_controller/metal/instrumentation.rb +19 -21
- data/lib/action_controller/metal/live.rb +90 -106
- data/lib/action_controller/metal/mime_responds.rb +33 -46
- data/lib/action_controller/metal/parameter_encoding.rb +51 -0
- data/lib/action_controller/metal/params_wrapper.rb +61 -53
- data/lib/action_controller/metal/redirecting.rb +49 -28
- data/lib/action_controller/metal/renderers.rb +87 -44
- data/lib/action_controller/metal/rendering.rb +72 -50
- data/lib/action_controller/metal/request_forgery_protection.rb +203 -92
- data/lib/action_controller/metal/rescue.rb +9 -16
- data/lib/action_controller/metal/streaming.rb +12 -10
- data/lib/action_controller/metal/strong_parameters.rb +582 -165
- data/lib/action_controller/metal/testing.rb +2 -17
- data/lib/action_controller/metal/url_for.rb +19 -10
- data/lib/action_controller/railtie.rb +28 -10
- data/lib/action_controller/railties/helpers.rb +2 -0
- data/lib/action_controller/renderer.rb +117 -0
- data/lib/action_controller/template_assertions.rb +11 -0
- data/lib/action_controller/test_case.rb +280 -411
- data/lib/action_dispatch.rb +27 -19
- data/lib/action_dispatch/http/cache.rb +93 -47
- data/lib/action_dispatch/http/content_security_policy.rb +272 -0
- data/lib/action_dispatch/http/filter_parameters.rb +26 -20
- data/lib/action_dispatch/http/filter_redirect.rb +10 -11
- data/lib/action_dispatch/http/headers.rb +55 -22
- data/lib/action_dispatch/http/mime_negotiation.rb +60 -41
- data/lib/action_dispatch/http/mime_type.rb +134 -121
- data/lib/action_dispatch/http/mime_types.rb +20 -6
- data/lib/action_dispatch/http/parameter_filter.rb +25 -11
- data/lib/action_dispatch/http/parameters.rb +98 -39
- data/lib/action_dispatch/http/rack_cache.rb +2 -0
- data/lib/action_dispatch/http/request.rb +200 -118
- data/lib/action_dispatch/http/response.rb +225 -110
- data/lib/action_dispatch/http/upload.rb +12 -6
- data/lib/action_dispatch/http/url.rb +110 -28
- data/lib/action_dispatch/journey.rb +7 -5
- data/lib/action_dispatch/journey/formatter.rb +55 -32
- data/lib/action_dispatch/journey/gtg/builder.rb +7 -5
- data/lib/action_dispatch/journey/gtg/simulator.rb +3 -9
- data/lib/action_dispatch/journey/gtg/transition_table.rb +17 -16
- data/lib/action_dispatch/journey/nfa/builder.rb +5 -3
- data/lib/action_dispatch/journey/nfa/dot.rb +13 -13
- data/lib/action_dispatch/journey/nfa/simulator.rb +3 -1
- data/lib/action_dispatch/journey/nfa/transition_table.rb +5 -48
- data/lib/action_dispatch/journey/nodes/node.rb +18 -6
- data/lib/action_dispatch/journey/parser.rb +23 -22
- data/lib/action_dispatch/journey/parser.y +3 -2
- data/lib/action_dispatch/journey/parser_extras.rb +12 -4
- data/lib/action_dispatch/journey/path/pattern.rb +50 -44
- data/lib/action_dispatch/journey/route.rb +106 -28
- data/lib/action_dispatch/journey/router.rb +35 -23
- data/lib/action_dispatch/journey/router/utils.rb +20 -11
- data/lib/action_dispatch/journey/routes.rb +18 -16
- data/lib/action_dispatch/journey/scanner.rb +18 -15
- data/lib/action_dispatch/journey/visitors.rb +99 -52
- data/lib/action_dispatch/middleware/callbacks.rb +1 -2
- data/lib/action_dispatch/middleware/cookies.rb +304 -193
- data/lib/action_dispatch/middleware/debug_exceptions.rb +152 -57
- data/lib/action_dispatch/middleware/debug_locks.rb +124 -0
- data/lib/action_dispatch/middleware/exception_wrapper.rb +68 -69
- data/lib/action_dispatch/middleware/executor.rb +21 -0
- data/lib/action_dispatch/middleware/flash.rb +78 -54
- data/lib/action_dispatch/middleware/public_exceptions.rb +27 -25
- data/lib/action_dispatch/middleware/reloader.rb +5 -91
- data/lib/action_dispatch/middleware/remote_ip.rb +41 -31
- data/lib/action_dispatch/middleware/request_id.rb +17 -9
- data/lib/action_dispatch/middleware/session/abstract_store.rb +41 -25
- data/lib/action_dispatch/middleware/session/cache_store.rb +24 -14
- data/lib/action_dispatch/middleware/session/cookie_store.rb +72 -67
- data/lib/action_dispatch/middleware/session/mem_cache_store.rb +8 -2
- data/lib/action_dispatch/middleware/show_exceptions.rb +26 -22
- data/lib/action_dispatch/middleware/ssl.rb +114 -36
- data/lib/action_dispatch/middleware/stack.rb +31 -44
- data/lib/action_dispatch/middleware/static.rb +57 -50
- data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb +2 -14
- data/lib/action_dispatch/middleware/templates/rescues/{_source.erb → _source.html.erb} +0 -0
- data/lib/action_dispatch/middleware/templates/rescues/_source.text.erb +8 -0
- data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.html.erb +21 -0
- data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.text.erb +13 -0
- data/lib/action_dispatch/middleware/templates/rescues/layout.erb +1 -0
- data/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb +1 -1
- data/lib/action_dispatch/middleware/templates/rescues/template_error.text.erb +1 -1
- data/lib/action_dispatch/middleware/templates/routes/_route.html.erb +4 -4
- data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +64 -64
- data/lib/action_dispatch/railtie.rb +19 -11
- data/lib/action_dispatch/request/session.rb +106 -59
- data/lib/action_dispatch/request/utils.rb +67 -24
- data/lib/action_dispatch/routing.rb +17 -18
- data/lib/action_dispatch/routing/endpoint.rb +9 -2
- data/lib/action_dispatch/routing/inspector.rb +58 -67
- data/lib/action_dispatch/routing/mapper.rb +734 -447
- data/lib/action_dispatch/routing/polymorphic_routes.rb +161 -139
- data/lib/action_dispatch/routing/redirection.rb +36 -26
- data/lib/action_dispatch/routing/route_set.rb +321 -291
- data/lib/action_dispatch/routing/routes_proxy.rb +32 -5
- data/lib/action_dispatch/routing/url_for.rb +65 -25
- data/lib/action_dispatch/system_test_case.rb +147 -0
- data/lib/action_dispatch/system_testing/browser.rb +49 -0
- data/lib/action_dispatch/system_testing/driver.rb +59 -0
- data/lib/action_dispatch/system_testing/server.rb +31 -0
- data/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb +96 -0
- data/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb +31 -0
- data/lib/action_dispatch/system_testing/test_helpers/undef_methods.rb +26 -0
- data/lib/action_dispatch/testing/assertion_response.rb +47 -0
- data/lib/action_dispatch/testing/assertions.rb +6 -4
- data/lib/action_dispatch/testing/assertions/response.rb +45 -20
- data/lib/action_dispatch/testing/assertions/routing.rb +30 -26
- data/lib/action_dispatch/testing/integration.rb +347 -209
- data/lib/action_dispatch/testing/request_encoder.rb +55 -0
- data/lib/action_dispatch/testing/test_process.rb +28 -22
- data/lib/action_dispatch/testing/test_request.rb +27 -34
- data/lib/action_dispatch/testing/test_response.rb +35 -7
- data/lib/action_pack.rb +4 -2
- data/lib/action_pack/gem_version.rb +5 -3
- data/lib/action_pack/version.rb +3 -1
- metadata +56 -39
- data/lib/action_controller/metal/hide_actions.rb +0 -40
- data/lib/action_controller/metal/rack_delegation.rb +0 -32
- data/lib/action_controller/middleware.rb +0 -39
- data/lib/action_controller/model_naming.rb +0 -12
- data/lib/action_dispatch/journey/backwards.rb +0 -5
- data/lib/action_dispatch/journey/router/strexp.rb +0 -27
- data/lib/action_dispatch/middleware/params_parser.rb +0 -60
- data/lib/action_dispatch/testing/assertions/dom.rb +0 -3
- data/lib/action_dispatch/testing/assertions/selector.rb +0 -3
- data/lib/action_dispatch/testing/assertions/tag.rb +0 -3
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module ActionDispatch
|
4
4
|
module Routing
|
@@ -6,7 +6,7 @@ module ActionDispatch
|
|
6
6
|
# given an Active Record model instance. They are to be used in combination with
|
7
7
|
# ActionController::Resources.
|
8
8
|
#
|
9
|
-
# These methods are useful when you want to generate correct URL or path to a RESTful
|
9
|
+
# These methods are useful when you want to generate the correct URL or path to a RESTful
|
10
10
|
# resource without having to know the exact type of the record in question.
|
11
11
|
#
|
12
12
|
# Nested resources and/or namespaces are also supported, as illustrated in the example:
|
@@ -42,7 +42,7 @@ module ActionDispatch
|
|
42
42
|
#
|
43
43
|
# Example usage:
|
44
44
|
#
|
45
|
-
# edit_polymorphic_path(@post)
|
45
|
+
# edit_polymorphic_path(@post) # => "/posts/1/edit"
|
46
46
|
# polymorphic_path(@post, format: :pdf) # => "/posts/1.pdf"
|
47
47
|
#
|
48
48
|
# == Usage with mounted engines
|
@@ -55,8 +55,6 @@ module ActionDispatch
|
|
55
55
|
# form_for([blog, @post]) # => "/blog/posts/1"
|
56
56
|
#
|
57
57
|
module PolymorphicRoutes
|
58
|
-
include ActionController::ModelNaming
|
59
|
-
|
60
58
|
# Constructs a call to a named RESTful route for the given record and returns the
|
61
59
|
# resulting URL string. For example:
|
62
60
|
#
|
@@ -83,7 +81,7 @@ module ActionDispatch
|
|
83
81
|
# polymorphic_url([blog, post], anchor: 'my_anchor', script_name: "/my_app")
|
84
82
|
# # => "http://example.com/my_app/blogs/1/posts/1#my_anchor"
|
85
83
|
#
|
86
|
-
# For all of these options, see the documentation for
|
84
|
+
# For all of these options, see the documentation for {url_for}[rdoc-ref:ActionDispatch::Routing::UrlFor].
|
87
85
|
#
|
88
86
|
# ==== Functionality
|
89
87
|
#
|
@@ -107,6 +105,10 @@ module ActionDispatch
|
|
107
105
|
return polymorphic_url record, options
|
108
106
|
end
|
109
107
|
|
108
|
+
if mapping = polymorphic_mapping(record_or_hash_or_array)
|
109
|
+
return mapping.call(self, [record_or_hash_or_array, options], false)
|
110
|
+
end
|
111
|
+
|
110
112
|
opts = options.dup
|
111
113
|
action = opts.delete :action
|
112
114
|
type = opts.delete(:routing_type) || :url
|
@@ -127,6 +129,10 @@ module ActionDispatch
|
|
127
129
|
return polymorphic_path record, options
|
128
130
|
end
|
129
131
|
|
132
|
+
if mapping = polymorphic_mapping(record_or_hash_or_array)
|
133
|
+
return mapping.call(self, [record_or_hash_or_array, options], true)
|
134
|
+
end
|
135
|
+
|
130
136
|
opts = options.dup
|
131
137
|
action = opts.delete :action
|
132
138
|
type = :path
|
@@ -138,7 +144,6 @@ module ActionDispatch
|
|
138
144
|
opts
|
139
145
|
end
|
140
146
|
|
141
|
-
|
142
147
|
%w(edit new).each do |action|
|
143
148
|
module_eval <<-EOT, __FILE__, __LINE__ + 1
|
144
149
|
def #{action}_polymorphic_url(record_or_hash, options = {})
|
@@ -153,178 +158,195 @@ module ActionDispatch
|
|
153
158
|
|
154
159
|
private
|
155
160
|
|
156
|
-
|
157
|
-
|
158
|
-
end
|
159
|
-
|
160
|
-
def polymorphic_path_for_action(action, record_or_hash, options)
|
161
|
-
polymorphic_path(record_or_hash, options.merge(:action => action))
|
162
|
-
end
|
163
|
-
|
164
|
-
class HelperMethodBuilder # :nodoc:
|
165
|
-
CACHE = { 'path' => {}, 'url' => {} }
|
166
|
-
|
167
|
-
def self.get(action, type)
|
168
|
-
type = type.to_s
|
169
|
-
CACHE[type].fetch(action) { build action, type }
|
161
|
+
def polymorphic_url_for_action(action, record_or_hash, options)
|
162
|
+
polymorphic_url(record_or_hash, options.merge(action: action))
|
170
163
|
end
|
171
164
|
|
172
|
-
def
|
173
|
-
|
165
|
+
def polymorphic_path_for_action(action, record_or_hash, options)
|
166
|
+
polymorphic_path(record_or_hash, options.merge(action: action))
|
167
|
+
end
|
174
168
|
|
175
|
-
def
|
176
|
-
|
177
|
-
|
178
|
-
if action.to_s == 'new'
|
179
|
-
HelperMethodBuilder.singular prefix, suffix
|
169
|
+
def polymorphic_mapping(record)
|
170
|
+
if record.respond_to?(:to_model)
|
171
|
+
_routes.polymorphic_mappings[record.to_model.model_name.name]
|
180
172
|
else
|
181
|
-
|
173
|
+
_routes.polymorphic_mappings[record.class.name]
|
182
174
|
end
|
183
175
|
end
|
184
176
|
|
185
|
-
|
186
|
-
|
187
|
-
end
|
177
|
+
class HelperMethodBuilder # :nodoc:
|
178
|
+
CACHE = { "path" => {}, "url" => {} }
|
188
179
|
|
189
|
-
|
190
|
-
|
191
|
-
|
180
|
+
def self.get(action, type)
|
181
|
+
type = type.to_s
|
182
|
+
CACHE[type].fetch(action) { build action, type }
|
183
|
+
end
|
192
184
|
|
193
|
-
|
194
|
-
|
185
|
+
def self.url; CACHE["url".freeze][nil]; end
|
186
|
+
def self.path; CACHE["path".freeze][nil]; end
|
195
187
|
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
if
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
recipient = record_or_hash_or_array.shift
|
188
|
+
def self.build(action, type)
|
189
|
+
prefix = action ? "#{action}_" : ""
|
190
|
+
suffix = type
|
191
|
+
if action.to_s == "new"
|
192
|
+
HelperMethodBuilder.singular prefix, suffix
|
193
|
+
else
|
194
|
+
HelperMethodBuilder.plural prefix, suffix
|
204
195
|
end
|
205
|
-
|
206
|
-
method, args = builder.handle_list record_or_hash_or_array
|
207
|
-
when String, Symbol
|
208
|
-
method, args = builder.handle_string record_or_hash_or_array
|
209
|
-
when Class
|
210
|
-
method, args = builder.handle_class record_or_hash_or_array
|
211
|
-
|
212
|
-
when nil
|
213
|
-
raise ArgumentError, "Nil location provided. Can't build URI."
|
214
|
-
else
|
215
|
-
method, args = builder.handle_model record_or_hash_or_array
|
216
196
|
end
|
217
197
|
|
198
|
+
def self.singular(prefix, suffix)
|
199
|
+
new(->(name) { name.singular_route_key }, prefix, suffix)
|
200
|
+
end
|
218
201
|
|
219
|
-
|
220
|
-
|
221
|
-
else
|
222
|
-
recipient.send(method, *args, options)
|
202
|
+
def self.plural(prefix, suffix)
|
203
|
+
new(->(name) { name.route_key }, prefix, suffix)
|
223
204
|
end
|
224
|
-
end
|
225
205
|
|
226
|
-
|
206
|
+
def self.polymorphic_method(recipient, record_or_hash_or_array, action, type, options)
|
207
|
+
builder = get action, type
|
208
|
+
|
209
|
+
case record_or_hash_or_array
|
210
|
+
when Array
|
211
|
+
record_or_hash_or_array = record_or_hash_or_array.compact
|
212
|
+
if record_or_hash_or_array.empty?
|
213
|
+
raise ArgumentError, "Nil location provided. Can't build URI."
|
214
|
+
end
|
215
|
+
if record_or_hash_or_array.first.is_a?(ActionDispatch::Routing::RoutesProxy)
|
216
|
+
recipient = record_or_hash_or_array.shift
|
217
|
+
end
|
218
|
+
|
219
|
+
method, args = builder.handle_list record_or_hash_or_array
|
220
|
+
when String, Symbol
|
221
|
+
method, args = builder.handle_string record_or_hash_or_array
|
222
|
+
when Class
|
223
|
+
method, args = builder.handle_class record_or_hash_or_array
|
227
224
|
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
225
|
+
when nil
|
226
|
+
raise ArgumentError, "Nil location provided. Can't build URI."
|
227
|
+
else
|
228
|
+
method, args = builder.handle_model record_or_hash_or_array
|
229
|
+
end
|
233
230
|
|
234
|
-
|
235
|
-
|
236
|
-
|
231
|
+
if options.empty?
|
232
|
+
recipient.send(method, *args)
|
233
|
+
else
|
234
|
+
recipient.send(method, *args, options)
|
235
|
+
end
|
236
|
+
end
|
237
237
|
|
238
|
-
|
239
|
-
target.send get_method_for_string str
|
240
|
-
end
|
238
|
+
attr_reader :suffix, :prefix
|
241
239
|
|
242
|
-
|
243
|
-
|
244
|
-
|
240
|
+
def initialize(key_strategy, prefix, suffix)
|
241
|
+
@key_strategy = key_strategy
|
242
|
+
@prefix = prefix
|
243
|
+
@suffix = suffix
|
244
|
+
end
|
245
245
|
|
246
|
-
|
247
|
-
|
248
|
-
|
246
|
+
def handle_string(record)
|
247
|
+
[get_method_for_string(record), []]
|
248
|
+
end
|
249
249
|
|
250
|
-
|
251
|
-
|
250
|
+
def handle_string_call(target, str)
|
251
|
+
target.send get_method_for_string str
|
252
|
+
end
|
252
253
|
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
model.model_name.singular_route_key
|
257
|
-
else
|
258
|
-
@key_strategy.call model.model_name
|
259
|
-
end
|
254
|
+
def handle_class(klass)
|
255
|
+
[get_method_for_class(klass), []]
|
256
|
+
end
|
260
257
|
|
261
|
-
|
258
|
+
def handle_class_call(target, klass)
|
259
|
+
target.send get_method_for_class klass
|
260
|
+
end
|
262
261
|
|
263
|
-
|
264
|
-
|
262
|
+
def handle_model(record)
|
263
|
+
args = []
|
265
264
|
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
265
|
+
model = record.to_model
|
266
|
+
named_route = if model.persisted?
|
267
|
+
args << model
|
268
|
+
get_method_for_string model.model_name.singular_route_key
|
269
|
+
else
|
270
|
+
get_method_for_class model
|
271
|
+
end
|
270
272
|
|
271
|
-
|
272
|
-
|
273
|
-
record = record_list.pop
|
273
|
+
[named_route, args]
|
274
|
+
end
|
274
275
|
|
275
|
-
|
276
|
+
def handle_model_call(target, record)
|
277
|
+
if mapping = polymorphic_mapping(target, record)
|
278
|
+
mapping.call(target, [record], suffix == "path")
|
279
|
+
else
|
280
|
+
method, args = handle_model(record)
|
281
|
+
target.send(method, *args)
|
282
|
+
end
|
283
|
+
end
|
276
284
|
|
277
|
-
|
278
|
-
|
285
|
+
def handle_list(list)
|
286
|
+
record_list = list.dup
|
287
|
+
record = record_list.pop
|
288
|
+
|
289
|
+
args = []
|
290
|
+
|
291
|
+
route = record_list.map { |parent|
|
292
|
+
case parent
|
293
|
+
when Symbol, String
|
294
|
+
parent.to_s
|
295
|
+
when Class
|
296
|
+
args << parent
|
297
|
+
parent.model_name.singular_route_key
|
298
|
+
else
|
299
|
+
args << parent.to_model
|
300
|
+
parent.to_model.model_name.singular_route_key
|
301
|
+
end
|
302
|
+
}
|
303
|
+
|
304
|
+
route <<
|
305
|
+
case record
|
279
306
|
when Symbol, String
|
280
|
-
|
307
|
+
record.to_s
|
281
308
|
when Class
|
282
|
-
|
283
|
-
parent.model_name.singular_route_key
|
309
|
+
@key_strategy.call record.model_name
|
284
310
|
else
|
285
|
-
|
286
|
-
|
311
|
+
model = record.to_model
|
312
|
+
if model.persisted?
|
313
|
+
args << model
|
314
|
+
model.model_name.singular_route_key
|
315
|
+
else
|
316
|
+
@key_strategy.call model.model_name
|
317
|
+
end
|
287
318
|
end
|
288
|
-
}
|
289
|
-
|
290
|
-
route <<
|
291
|
-
case record
|
292
|
-
when Symbol, String
|
293
|
-
record.to_s
|
294
|
-
when Class
|
295
|
-
@key_strategy.call record.model_name
|
296
|
-
else
|
297
|
-
model = record.to_model
|
298
|
-
if model.persisted?
|
299
|
-
args << model
|
300
|
-
model.model_name.singular_route_key
|
301
|
-
else
|
302
|
-
@key_strategy.call model.model_name
|
303
|
-
end
|
304
|
-
end
|
305
319
|
|
306
|
-
|
320
|
+
route << suffix
|
307
321
|
|
308
|
-
|
309
|
-
|
310
|
-
|
322
|
+
named_route = prefix + route.join("_")
|
323
|
+
[named_route, args]
|
324
|
+
end
|
311
325
|
|
312
|
-
|
326
|
+
private
|
313
327
|
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
328
|
+
def polymorphic_mapping(target, record)
|
329
|
+
if record.respond_to?(:to_model)
|
330
|
+
target._routes.polymorphic_mappings[record.to_model.model_name.name]
|
331
|
+
else
|
332
|
+
target._routes.polymorphic_mappings[record.class.name]
|
333
|
+
end
|
334
|
+
end
|
318
335
|
|
319
|
-
|
320
|
-
|
321
|
-
|
336
|
+
def get_method_for_class(klass)
|
337
|
+
name = @key_strategy.call klass.model_name
|
338
|
+
get_method_for_string name
|
339
|
+
end
|
322
340
|
|
323
|
-
|
324
|
-
|
325
|
-
|
341
|
+
def get_method_for_string(str)
|
342
|
+
"#{prefix}#{str}_#{suffix}"
|
343
|
+
end
|
344
|
+
|
345
|
+
[nil, "new", "edit"].each do |action|
|
346
|
+
CACHE["url"][action] = build action, "url"
|
347
|
+
CACHE["path"][action] = build action, "path"
|
348
|
+
end
|
326
349
|
end
|
327
|
-
end
|
328
350
|
end
|
329
351
|
end
|
330
352
|
end
|
@@ -1,9 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "action_dispatch/http/request"
|
4
|
+
require "active_support/core_ext/uri"
|
5
|
+
require "active_support/core_ext/array/extract_options"
|
6
|
+
require "rack/utils"
|
7
|
+
require "action_controller/metal/exceptions"
|
8
|
+
require "action_dispatch/routing/endpoint"
|
7
9
|
|
8
10
|
module ActionDispatch
|
9
11
|
module Routing
|
@@ -22,9 +24,8 @@ module ActionDispatch
|
|
22
24
|
end
|
23
25
|
|
24
26
|
def serve(req)
|
25
|
-
req.check_path_parameters!
|
26
27
|
uri = URI.parse(path(req.path_parameters, req))
|
27
|
-
|
28
|
+
|
28
29
|
unless uri.host
|
29
30
|
if relative_path?(uri.path)
|
30
31
|
uri.path = "#{req.script_name}/#{uri.path}"
|
@@ -32,17 +33,19 @@ module ActionDispatch
|
|
32
33
|
uri.path = req.script_name.empty? ? "/" : req.script_name
|
33
34
|
end
|
34
35
|
end
|
35
|
-
|
36
|
+
|
36
37
|
uri.scheme ||= req.scheme
|
37
38
|
uri.host ||= req.host
|
38
39
|
uri.port ||= req.port unless req.standard_port?
|
39
40
|
|
41
|
+
req.commit_flash
|
42
|
+
|
40
43
|
body = %(<html><body>You are being <a href="#{ERB::Util.unwrapped_html_escape(uri.to_s)}">redirected</a>.</body></html>)
|
41
44
|
|
42
45
|
headers = {
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
+
"Location" => uri.to_s,
|
47
|
+
"Content-Type" => "text/html",
|
48
|
+
"Content-Length" => body.length.to_s
|
46
49
|
}
|
47
50
|
|
48
51
|
[ status, headers, [body] ]
|
@@ -58,19 +61,19 @@ module ActionDispatch
|
|
58
61
|
|
59
62
|
private
|
60
63
|
def relative_path?(path)
|
61
|
-
path && !path.empty? && path[0] !=
|
64
|
+
path && !path.empty? && path[0] != "/"
|
62
65
|
end
|
63
66
|
|
64
67
|
def escape(params)
|
65
|
-
Hash[params.map{ |k,v| [k, Rack::Utils.escape(v)] }]
|
68
|
+
Hash[params.map { |k, v| [k, Rack::Utils.escape(v)] }]
|
66
69
|
end
|
67
70
|
|
68
71
|
def escape_fragment(params)
|
69
|
-
Hash[params.map{ |k,v| [k, Journey::Router::Utils.escape_fragment(v)] }]
|
72
|
+
Hash[params.map { |k, v| [k, Journey::Router::Utils.escape_fragment(v)] }]
|
70
73
|
end
|
71
74
|
|
72
75
|
def escape_path(params)
|
73
|
-
Hash[params.map{ |k,v| [k, Journey::Router::Utils.escape_path(v)] }]
|
76
|
+
Hash[params.map { |k, v| [k, Journey::Router::Utils.escape_path(v)] }]
|
74
77
|
end
|
75
78
|
end
|
76
79
|
|
@@ -104,11 +107,11 @@ module ActionDispatch
|
|
104
107
|
|
105
108
|
def path(params, request)
|
106
109
|
url_options = {
|
107
|
-
:
|
108
|
-
:
|
109
|
-
:
|
110
|
-
:
|
111
|
-
:
|
110
|
+
protocol: request.protocol,
|
111
|
+
host: request.host,
|
112
|
+
port: request.optional_port,
|
113
|
+
path: request.path,
|
114
|
+
params: request.query_parameters
|
112
115
|
}.merge! options
|
113
116
|
|
114
117
|
if !params.empty? && url_options[:path].match(/%\{\w*\}/)
|
@@ -124,26 +127,28 @@ module ActionDispatch
|
|
124
127
|
url_options[:script_name] = request.script_name
|
125
128
|
end
|
126
129
|
end
|
127
|
-
|
130
|
+
|
128
131
|
ActionDispatch::Http::URL.url_for url_options
|
129
132
|
end
|
130
133
|
|
131
134
|
def inspect
|
132
|
-
"redirect(#{status}, #{options.map{ |k,v| "#{k}: #{v}" }.join(', ')})"
|
135
|
+
"redirect(#{status}, #{options.map { |k, v| "#{k}: #{v}" }.join(', ')})"
|
133
136
|
end
|
134
137
|
end
|
135
138
|
|
136
139
|
module Redirection
|
137
|
-
|
138
140
|
# Redirect any path to another path:
|
139
141
|
#
|
140
142
|
# get "/stories" => redirect("/posts")
|
141
143
|
#
|
144
|
+
# This will redirect the user, while ignoring certain parts of the request, including query string, etc.
|
145
|
+
# <tt>/stories</tt>, <tt>/stories?foo=bar</tt>, etc all redirect to <tt>/posts</tt>.
|
146
|
+
#
|
142
147
|
# You can also use interpolation in the supplied redirect argument:
|
143
148
|
#
|
144
149
|
# get 'docs/:article', to: redirect('/wiki/%{article}')
|
145
150
|
#
|
146
|
-
# Note that if you return a path without a leading slash then the
|
151
|
+
# Note that if you return a path without a leading slash then the URL is prefixed with the
|
147
152
|
# current SCRIPT_NAME environment variable. This is typically '/' but may be different in
|
148
153
|
# a mounted engine or where the application is deployed to a subdirectory of a website.
|
149
154
|
#
|
@@ -162,11 +167,16 @@ module ActionDispatch
|
|
162
167
|
# Note that the +do end+ syntax for the redirect block wouldn't work, as Ruby would pass
|
163
168
|
# the block to +get+ instead of +redirect+. Use <tt>{ ... }</tt> instead.
|
164
169
|
#
|
165
|
-
# The options version of redirect allows you to supply only the parts of the
|
170
|
+
# The options version of redirect allows you to supply only the parts of the URL which need
|
166
171
|
# to change, it also supports interpolation of the path similar to the first example.
|
167
172
|
#
|
168
173
|
# get 'stores/:name', to: redirect(subdomain: 'stores', path: '/%{name}')
|
169
174
|
# get 'stores/:name(*all)', to: redirect(subdomain: 'stores', path: '/%{name}%{all}')
|
175
|
+
# get '/stories', to: redirect(path: '/posts')
|
176
|
+
#
|
177
|
+
# This will redirect the user, while changing only the specified parts of the request,
|
178
|
+
# for example the +path+ option in the last example.
|
179
|
+
# <tt>/stories</tt>, <tt>/stories?foo=bar</tt>, redirect to <tt>/posts</tt> and <tt>/posts?foo=bar</tt> respectively.
|
170
180
|
#
|
171
181
|
# Finally, an object which responds to call can be supplied to redirect, allowing you to reuse
|
172
182
|
# common redirect routes. The call method must accept two arguments, params and request, and return
|