actionpack 5.1.7 → 5.2.0.beta1
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 +132 -490
- data/README.rdoc +1 -1
- data/lib/abstract_controller.rb +2 -0
- data/lib/abstract_controller/asset_paths.rb +2 -0
- data/lib/abstract_controller/base.rb +10 -2
- data/lib/abstract_controller/caching.rb +3 -2
- data/lib/abstract_controller/caching/fragments.rb +30 -7
- data/lib/abstract_controller/callbacks.rb +25 -3
- data/lib/abstract_controller/collector.rb +2 -0
- data/lib/abstract_controller/error.rb +2 -0
- data/lib/abstract_controller/helpers.rb +4 -5
- data/lib/abstract_controller/logger.rb +2 -0
- data/lib/abstract_controller/railties/routes_helpers.rb +2 -0
- data/lib/abstract_controller/rendering.rb +9 -16
- data/lib/abstract_controller/translation.rb +2 -0
- data/lib/abstract_controller/url_for.rb +2 -0
- data/lib/action_controller.rb +3 -0
- data/lib/action_controller/api.rb +2 -0
- data/lib/action_controller/api/api_rendering.rb +2 -0
- data/lib/action_controller/base.rb +3 -0
- data/lib/action_controller/caching.rb +2 -0
- data/lib/action_controller/form_builder.rb +2 -0
- data/lib/action_controller/log_subscriber.rb +5 -3
- data/lib/action_controller/metal.rb +3 -2
- data/lib/action_controller/metal/basic_implicit_render.rb +2 -0
- data/lib/action_controller/metal/conditional_get.rb +4 -3
- data/lib/action_controller/metal/content_security_policy.rb +26 -0
- data/lib/action_controller/metal/cookies.rb +2 -0
- data/lib/action_controller/metal/data_streaming.rb +7 -5
- data/lib/action_controller/metal/etag_with_flash.rb +2 -0
- data/lib/action_controller/metal/etag_with_template_digest.rb +3 -2
- data/lib/action_controller/metal/exceptions.rb +2 -3
- data/lib/action_controller/metal/flash.rb +3 -2
- data/lib/action_controller/metal/force_ssl.rb +2 -0
- data/lib/action_controller/metal/head.rb +2 -0
- data/lib/action_controller/metal/helpers.rb +4 -3
- data/lib/action_controller/metal/http_authentication.rb +8 -9
- data/lib/action_controller/metal/implicit_render.rb +2 -0
- data/lib/action_controller/metal/instrumentation.rb +4 -6
- data/lib/action_controller/metal/live.rb +3 -1
- data/lib/action_controller/metal/mime_responds.rb +3 -1
- data/lib/action_controller/metal/parameter_encoding.rb +2 -0
- data/lib/action_controller/metal/params_wrapper.rb +13 -9
- data/lib/action_controller/metal/redirecting.rb +21 -10
- data/lib/action_controller/metal/renderers.rb +4 -3
- data/lib/action_controller/metal/rendering.rb +2 -2
- data/lib/action_controller/metal/request_forgery_protection.rb +22 -6
- data/lib/action_controller/metal/rescue.rb +5 -3
- data/lib/action_controller/metal/streaming.rb +2 -0
- data/lib/action_controller/metal/strong_parameters.rb +19 -11
- data/lib/action_controller/metal/testing.rb +2 -6
- data/lib/action_controller/metal/url_for.rb +2 -0
- data/lib/action_controller/railtie.rb +16 -4
- data/lib/action_controller/railties/helpers.rb +2 -0
- data/lib/action_controller/renderer.rb +2 -0
- data/lib/action_controller/template_assertions.rb +2 -0
- data/lib/action_controller/test_case.rb +4 -1
- data/lib/action_dispatch.rb +3 -0
- data/lib/action_dispatch/http/cache.rb +15 -9
- data/lib/action_dispatch/http/content_security_policy.rb +233 -0
- data/lib/action_dispatch/http/filter_parameters.rb +4 -2
- data/lib/action_dispatch/http/filter_redirect.rb +2 -0
- data/lib/action_dispatch/http/headers.rb +2 -0
- data/lib/action_dispatch/http/mime_negotiation.rb +4 -13
- data/lib/action_dispatch/http/mime_type.rb +15 -13
- data/lib/action_dispatch/http/mime_types.rb +4 -2
- data/lib/action_dispatch/http/parameter_filter.rb +2 -0
- data/lib/action_dispatch/http/parameters.rb +6 -9
- data/lib/action_dispatch/http/rack_cache.rb +2 -0
- data/lib/action_dispatch/http/request.rb +36 -16
- data/lib/action_dispatch/http/response.rb +11 -9
- data/lib/action_dispatch/http/upload.rb +2 -0
- data/lib/action_dispatch/http/url.rb +4 -5
- data/lib/action_dispatch/journey.rb +2 -0
- data/lib/action_dispatch/journey/formatter.rb +4 -2
- data/lib/action_dispatch/journey/gtg/builder.rb +2 -0
- data/lib/action_dispatch/journey/gtg/simulator.rb +2 -8
- data/lib/action_dispatch/journey/gtg/transition_table.rb +3 -2
- data/lib/action_dispatch/journey/nfa/builder.rb +2 -0
- data/lib/action_dispatch/journey/nfa/dot.rb +2 -0
- data/lib/action_dispatch/journey/nfa/simulator.rb +2 -0
- data/lib/action_dispatch/journey/nfa/transition_table.rb +2 -0
- data/lib/action_dispatch/journey/nodes/node.rb +2 -0
- data/lib/action_dispatch/journey/parser_extras.rb +2 -0
- data/lib/action_dispatch/journey/path/pattern.rb +2 -0
- data/lib/action_dispatch/journey/route.rb +15 -6
- data/lib/action_dispatch/journey/router.rb +3 -1
- data/lib/action_dispatch/journey/router/utils.rb +14 -7
- data/lib/action_dispatch/journey/routes.rb +2 -1
- data/lib/action_dispatch/journey/scanner.rb +1 -0
- data/lib/action_dispatch/journey/visitors.rb +5 -3
- data/lib/action_dispatch/middleware/callbacks.rb +2 -0
- data/lib/action_dispatch/middleware/cookies.rb +141 -91
- data/lib/action_dispatch/middleware/debug_exceptions.rb +4 -2
- data/lib/action_dispatch/middleware/debug_locks.rb +9 -7
- data/lib/action_dispatch/middleware/exception_wrapper.rb +4 -6
- data/lib/action_dispatch/middleware/executor.rb +2 -0
- data/lib/action_dispatch/middleware/flash.rb +3 -1
- data/lib/action_dispatch/middleware/public_exceptions.rb +6 -4
- data/lib/action_dispatch/middleware/reloader.rb +2 -0
- data/lib/action_dispatch/middleware/remote_ip.rb +7 -5
- data/lib/action_dispatch/middleware/request_id.rb +2 -0
- data/lib/action_dispatch/middleware/session/abstract_store.rb +3 -1
- data/lib/action_dispatch/middleware/session/cache_store.rb +2 -0
- data/lib/action_dispatch/middleware/session/cookie_store.rb +13 -25
- data/lib/action_dispatch/middleware/session/mem_cache_store.rb +2 -0
- data/lib/action_dispatch/middleware/show_exceptions.rb +3 -1
- data/lib/action_dispatch/middleware/ssl.rb +42 -37
- data/lib/action_dispatch/middleware/stack.rb +2 -0
- data/lib/action_dispatch/middleware/static.rb +10 -8
- data/lib/action_dispatch/middleware/templates/rescues/layout.erb +1 -0
- data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +6 -2
- data/lib/action_dispatch/railtie.rb +7 -0
- data/lib/action_dispatch/request/session.rb +8 -4
- data/lib/action_dispatch/request/utils.rb +4 -4
- data/lib/action_dispatch/routing.rb +3 -1
- data/lib/action_dispatch/routing/endpoint.rb +8 -4
- data/lib/action_dispatch/routing/inspector.rb +5 -3
- data/lib/action_dispatch/routing/mapper.rb +62 -51
- data/lib/action_dispatch/routing/polymorphic_routes.rb +2 -0
- data/lib/action_dispatch/routing/redirection.rb +7 -5
- data/lib/action_dispatch/routing/route_set.rb +26 -33
- data/lib/action_dispatch/routing/routes_proxy.rb +5 -2
- data/lib/action_dispatch/routing/url_for.rb +6 -4
- data/lib/action_dispatch/system_test_case.rb +14 -6
- data/lib/action_dispatch/system_testing/driver.rb +20 -2
- data/lib/action_dispatch/system_testing/server.rb +2 -16
- data/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb +6 -4
- data/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb +2 -0
- data/lib/action_dispatch/system_testing/test_helpers/undef_methods.rb +26 -0
- data/lib/action_dispatch/testing/assertion_response.rb +2 -0
- data/lib/action_dispatch/testing/assertions.rb +2 -0
- data/lib/action_dispatch/testing/assertions/response.rb +4 -2
- data/lib/action_dispatch/testing/assertions/routing.rb +5 -5
- data/lib/action_dispatch/testing/integration.rb +24 -21
- data/lib/action_dispatch/testing/request_encoder.rb +2 -0
- data/lib/action_dispatch/testing/test_process.rb +2 -0
- data/lib/action_dispatch/testing/test_request.rb +3 -1
- data/lib/action_dispatch/testing/test_response.rb +23 -3
- data/lib/action_pack.rb +2 -0
- data/lib/action_pack/gem_version.rb +5 -3
- data/lib/action_pack/version.rb +2 -0
- metadata +17 -13
@@ -17,6 +17,10 @@
|
|
17
17
|
line-height: 15px;
|
18
18
|
}
|
19
19
|
|
20
|
+
#route_table thead tr.bottom th input#search {
|
21
|
+
-webkit-appearance: textfield;
|
22
|
+
}
|
23
|
+
|
20
24
|
#route_table tbody tr {
|
21
25
|
border-bottom: 1px solid #ddd;
|
22
26
|
}
|
@@ -60,7 +64,7 @@
|
|
60
64
|
<%= link_to "Path", "#", 'data-route-helper' => '_path',
|
61
65
|
title: "Returns a relative path (without the http or domain)" %> /
|
62
66
|
<%= link_to "Url", "#", 'data-route-helper' => '_url',
|
63
|
-
title: "Returns an absolute
|
67
|
+
title: "Returns an absolute URL (with the http and domain)" %>
|
64
68
|
</th>
|
65
69
|
<th><%# HTTP Verb %>
|
66
70
|
</th>
|
@@ -93,7 +97,7 @@
|
|
93
97
|
}
|
94
98
|
}
|
95
99
|
|
96
|
-
// get JSON from
|
100
|
+
// get JSON from URL and invoke callback with result
|
97
101
|
function getJSON(url, success) {
|
98
102
|
var xhr = new XMLHttpRequest();
|
99
103
|
xhr.open('GET', url);
|
@@ -1,4 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "action_dispatch"
|
4
|
+
require "active_support/messages/rotation_configuration"
|
2
5
|
|
3
6
|
module ActionDispatch
|
4
7
|
class Railtie < Rails::Railtie # :nodoc:
|
@@ -16,6 +19,8 @@ module ActionDispatch
|
|
16
19
|
config.action_dispatch.signed_cookie_salt = "signed cookie"
|
17
20
|
config.action_dispatch.encrypted_cookie_salt = "encrypted cookie"
|
18
21
|
config.action_dispatch.encrypted_signed_cookie_salt = "signed encrypted cookie"
|
22
|
+
config.action_dispatch.authenticated_encrypted_cookie_salt = "authenticated encrypted cookie"
|
23
|
+
config.action_dispatch.use_authenticated_cookie_encryption = false
|
19
24
|
config.action_dispatch.perform_deep_munge = true
|
20
25
|
|
21
26
|
config.action_dispatch.default_headers = {
|
@@ -24,6 +29,8 @@ module ActionDispatch
|
|
24
29
|
"X-Content-Type-Options" => "nosniff"
|
25
30
|
}
|
26
31
|
|
32
|
+
config.action_dispatch.cookies_rotations = ActiveSupport::Messages::RotationConfiguration.new
|
33
|
+
|
27
34
|
config.eager_load_namespaces << ActionDispatch
|
28
35
|
|
29
36
|
initializer "action_dispatch.configure" do |app|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "rack/session/abstract/id"
|
2
4
|
|
3
5
|
module ActionDispatch
|
@@ -7,10 +9,10 @@ module ActionDispatch
|
|
7
9
|
ENV_SESSION_KEY = Rack::RACK_SESSION # :nodoc:
|
8
10
|
ENV_SESSION_OPTIONS_KEY = Rack::RACK_SESSION_OPTIONS # :nodoc:
|
9
11
|
|
10
|
-
# Singleton object used to determine if an optional param wasn't specified
|
12
|
+
# Singleton object used to determine if an optional param wasn't specified.
|
11
13
|
Unspecified = Object.new
|
12
14
|
|
13
|
-
# Creates a session hash, merging the properties of the previous session if any
|
15
|
+
# Creates a session hash, merging the properties of the previous session if any.
|
14
16
|
def self.create(store, req, default_options)
|
15
17
|
session_was = find req
|
16
18
|
session = Request::Session.new(store, req)
|
@@ -63,7 +65,7 @@ module ActionDispatch
|
|
63
65
|
@req = req
|
64
66
|
@delegate = {}
|
65
67
|
@loaded = false
|
66
|
-
@exists = nil #
|
68
|
+
@exists = nil # We haven't checked yet.
|
67
69
|
end
|
68
70
|
|
69
71
|
def id
|
@@ -79,7 +81,7 @@ module ActionDispatch
|
|
79
81
|
options = self.options || {}
|
80
82
|
@by.send(:delete_session, @req, options.id(@req), options)
|
81
83
|
|
82
|
-
# Load the new sid to be written with the response
|
84
|
+
# Load the new sid to be written with the response.
|
83
85
|
@loaded = false
|
84
86
|
load_for_write!
|
85
87
|
end
|
@@ -101,11 +103,13 @@ module ActionDispatch
|
|
101
103
|
|
102
104
|
# Returns keys of the session as Array.
|
103
105
|
def keys
|
106
|
+
load_for_read!
|
104
107
|
@delegate.keys
|
105
108
|
end
|
106
109
|
|
107
110
|
# Returns values of the session as Array.
|
108
111
|
def values
|
112
|
+
load_for_read!
|
109
113
|
@delegate.values
|
110
114
|
end
|
111
115
|
|
@@ -1,8 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActionDispatch
|
2
4
|
class Request
|
3
5
|
class Utils # :nodoc:
|
4
|
-
mattr_accessor :perform_deep_munge
|
5
|
-
self.perform_deep_munge = true
|
6
|
+
mattr_accessor :perform_deep_munge, default: true
|
6
7
|
|
7
8
|
def self.each_param_value(params, &block)
|
8
9
|
case params
|
@@ -40,7 +41,6 @@ module ActionDispatch
|
|
40
41
|
|
41
42
|
class ParamEncoder # :nodoc:
|
42
43
|
# Convert nested Hash to HashWithIndifferentAccess.
|
43
|
-
#
|
44
44
|
def self.normalize_encode_params(params)
|
45
45
|
case params
|
46
46
|
when Array
|
@@ -63,7 +63,7 @@ module ActionDispatch
|
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
|
-
# Remove nils from the params hash
|
66
|
+
# Remove nils from the params hash.
|
67
67
|
class NoNilParamEncoder < ParamEncoder # :nodoc:
|
68
68
|
def self.handle_array(params)
|
69
69
|
list = super
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "active_support/core_ext/string/filters"
|
2
4
|
|
3
5
|
module ActionDispatch
|
@@ -120,7 +122,7 @@ module ActionDispatch
|
|
120
122
|
# controller :blog do
|
121
123
|
# get 'blog/show' => :list
|
122
124
|
# get 'blog/delete' => :delete
|
123
|
-
# get 'blog/edit'
|
125
|
+
# get 'blog/edit' => :edit
|
124
126
|
# end
|
125
127
|
#
|
126
128
|
# # provides named routes for show, delete, and edit
|
@@ -1,10 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActionDispatch
|
2
4
|
module Routing
|
3
5
|
class Endpoint # :nodoc:
|
4
|
-
def dispatcher?;
|
5
|
-
def redirect?;
|
6
|
-
def
|
7
|
-
def
|
6
|
+
def dispatcher?; false; end
|
7
|
+
def redirect?; false; end
|
8
|
+
def engine?; rack_app.respond_to?(:routes); end
|
9
|
+
def matches?(req); true; end
|
10
|
+
def app; self; end
|
11
|
+
def rack_app; app; end
|
8
12
|
end
|
9
13
|
end
|
10
14
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "delegate"
|
2
4
|
require "active_support/core_ext/string/strip"
|
3
5
|
|
@@ -13,7 +15,7 @@ module ActionDispatch
|
|
13
15
|
end
|
14
16
|
|
15
17
|
def rack_app
|
16
|
-
app.
|
18
|
+
app.rack_app
|
17
19
|
end
|
18
20
|
|
19
21
|
def path
|
@@ -45,7 +47,7 @@ module ActionDispatch
|
|
45
47
|
end
|
46
48
|
|
47
49
|
def engine?
|
48
|
-
|
50
|
+
app.engine?
|
49
51
|
end
|
50
52
|
end
|
51
53
|
|
@@ -196,7 +198,7 @@ module ActionDispatch
|
|
196
198
|
@buffer << @view.render(partial: "routes/route", collection: routes)
|
197
199
|
end
|
198
200
|
|
199
|
-
#
|
201
|
+
# The header is part of the HTML page, so we don't construct it here.
|
200
202
|
def header(routes)
|
201
203
|
end
|
202
204
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "active_support/core_ext/hash/slice"
|
2
4
|
require "active_support/core_ext/enumerable"
|
3
5
|
require "active_support/core_ext/array/extract_options"
|
@@ -17,9 +19,9 @@ module ActionDispatch
|
|
17
19
|
CALL = ->(app, req) { app.call req.env }
|
18
20
|
|
19
21
|
def initialize(app, constraints, strategy)
|
20
|
-
# Unwrap Constraints objects.
|
22
|
+
# Unwrap Constraints objects. I don't actually think it's possible
|
21
23
|
# to pass a Constraints object to this constructor, but there were
|
22
|
-
# multiple places that kept testing children of this object.
|
24
|
+
# multiple places that kept testing children of this object. I
|
23
25
|
# *think* they were just being defensive, but I have no idea.
|
24
26
|
if app.is_a?(self.class)
|
25
27
|
constraints += app.constraints
|
@@ -219,7 +221,7 @@ module ActionDispatch
|
|
219
221
|
private
|
220
222
|
def add_wildcard_options(options, formatted, path_ast)
|
221
223
|
# Add a constraint for wildcard route to make it non-greedy and match the
|
222
|
-
# optional format part of the route by default
|
224
|
+
# optional format part of the route by default.
|
223
225
|
if formatted != false
|
224
226
|
path_ast.grep(Journey::Nodes::Star).each_with_object({}) { |node, hash|
|
225
227
|
hash[node.name.to_sym] ||= /.+?/
|
@@ -306,7 +308,7 @@ module ActionDispatch
|
|
306
308
|
def check_controller_and_action(path_params, controller, action)
|
307
309
|
hash = check_part(:controller, controller, path_params, {}) do |part|
|
308
310
|
translate_controller(part) {
|
309
|
-
message = "'#{part}' is not a supported controller name. This can lead to potential routing problems."
|
311
|
+
message = "'#{part}' is not a supported controller name. This can lead to potential routing problems.".dup
|
310
312
|
message << " See http://guides.rubyonrails.org/routing.html#specifying-a-controller-to-use"
|
311
313
|
|
312
314
|
raise ArgumentError, message
|
@@ -397,7 +399,7 @@ module ActionDispatch
|
|
397
399
|
end
|
398
400
|
|
399
401
|
module Base
|
400
|
-
# Matches a
|
402
|
+
# Matches a URL pattern to one or more routes.
|
401
403
|
#
|
402
404
|
# You should not use the +match+ method in your router
|
403
405
|
# without specifying an HTTP method.
|
@@ -407,7 +409,7 @@ module ActionDispatch
|
|
407
409
|
# # sets :controller, :action and :id in params
|
408
410
|
# match ':controller/:action/:id', via: [:get, :post]
|
409
411
|
#
|
410
|
-
# Note that +:controller+, +:action+ and +:id+ are interpreted as
|
412
|
+
# Note that +:controller+, +:action+ and +:id+ are interpreted as URL
|
411
413
|
# query parameters and thus available through +params+ in an action.
|
412
414
|
#
|
413
415
|
# If you want to expose your action to GET, use +get+ in the router:
|
@@ -456,7 +458,7 @@ module ActionDispatch
|
|
456
458
|
#
|
457
459
|
# === Options
|
458
460
|
#
|
459
|
-
# Any options not seen here are passed on as params with the
|
461
|
+
# Any options not seen here are passed on as params with the URL.
|
460
462
|
#
|
461
463
|
# [:controller]
|
462
464
|
# The route's controller.
|
@@ -471,7 +473,17 @@ module ActionDispatch
|
|
471
473
|
# <tt>params[<:param>]</tt>.
|
472
474
|
# In your router:
|
473
475
|
#
|
474
|
-
# resources :
|
476
|
+
# resources :users, param: :name
|
477
|
+
#
|
478
|
+
# The +users+ resource here will have the following routes generated for it:
|
479
|
+
#
|
480
|
+
# GET /users(.:format)
|
481
|
+
# POST /users(.:format)
|
482
|
+
# GET /users/new(.:format)
|
483
|
+
# GET /users/:name/edit(.:format)
|
484
|
+
# GET /users/:name(.:format)
|
485
|
+
# PATCH/PUT /users/:name(.:format)
|
486
|
+
# DELETE /users/:name(.:format)
|
475
487
|
#
|
476
488
|
# You can override <tt>ActiveRecord::Base#to_param</tt> of a related
|
477
489
|
# model to construct a URL:
|
@@ -482,8 +494,8 @@ module ActionDispatch
|
|
482
494
|
# end
|
483
495
|
# end
|
484
496
|
#
|
485
|
-
#
|
486
|
-
#
|
497
|
+
# user = User.find_by(name: 'Phusion')
|
498
|
+
# user_path(user) # => "/users/Phusion"
|
487
499
|
#
|
488
500
|
# [:path]
|
489
501
|
# The path prefix for the routes.
|
@@ -652,7 +664,6 @@ module ActionDispatch
|
|
652
664
|
def define_generate_prefix(app, name)
|
653
665
|
_route = @set.named_routes.get name
|
654
666
|
_routes = @set
|
655
|
-
_url_helpers = @set.url_helpers
|
656
667
|
|
657
668
|
script_namer = ->(options) do
|
658
669
|
prefix_options = options.slice(*_route.segment_keys)
|
@@ -664,7 +675,7 @@ module ActionDispatch
|
|
664
675
|
|
665
676
|
# We must actually delete prefix segment keys to avoid passing them to next url_for.
|
666
677
|
_route.segment_keys.each { |k| options.delete(k) }
|
667
|
-
|
678
|
+
_routes.url_helpers.send("#{name}_path", prefix_options)
|
668
679
|
end
|
669
680
|
|
670
681
|
app.routes.define_mounted_helper(name, script_namer)
|
@@ -1252,7 +1263,7 @@ module ActionDispatch
|
|
1252
1263
|
#
|
1253
1264
|
# resource :profile
|
1254
1265
|
#
|
1255
|
-
# creates six different routes in your application, all mapping to
|
1266
|
+
# This creates six different routes in your application, all mapping to
|
1256
1267
|
# the +Profiles+ controller (note that the controller is named after
|
1257
1268
|
# the plural):
|
1258
1269
|
#
|
@@ -1264,7 +1275,7 @@ module ActionDispatch
|
|
1264
1275
|
# POST /profile
|
1265
1276
|
#
|
1266
1277
|
# === Options
|
1267
|
-
# Takes same options as
|
1278
|
+
# Takes same options as resources[rdoc-ref:#resources]
|
1268
1279
|
def resource(*resources, &block)
|
1269
1280
|
options = resources.extract_options!.dup
|
1270
1281
|
|
@@ -1329,7 +1340,7 @@ module ActionDispatch
|
|
1329
1340
|
# DELETE /photos/:photo_id/comments/:id
|
1330
1341
|
#
|
1331
1342
|
# === Options
|
1332
|
-
# Takes same options as
|
1343
|
+
# Takes same options as match[rdoc-ref:Base#match] as well as:
|
1333
1344
|
#
|
1334
1345
|
# [:path_names]
|
1335
1346
|
# Allows you to change the segment component of the +edit+ and +new+ actions.
|
@@ -1337,14 +1348,14 @@ module ActionDispatch
|
|
1337
1348
|
#
|
1338
1349
|
# resources :posts, path_names: { new: "brand_new" }
|
1339
1350
|
#
|
1340
|
-
# The above example will now change /posts/new to /posts/brand_new
|
1351
|
+
# The above example will now change /posts/new to /posts/brand_new.
|
1341
1352
|
#
|
1342
1353
|
# [:path]
|
1343
1354
|
# Allows you to change the path prefix for the resource.
|
1344
1355
|
#
|
1345
1356
|
# resources :posts, path: 'postings'
|
1346
1357
|
#
|
1347
|
-
# The resource and all segments will now route to /postings instead of /posts
|
1358
|
+
# The resource and all segments will now route to /postings instead of /posts.
|
1348
1359
|
#
|
1349
1360
|
# [:only]
|
1350
1361
|
# Only generate routes for the given actions.
|
@@ -1539,7 +1550,7 @@ module ActionDispatch
|
|
1539
1550
|
end
|
1540
1551
|
end
|
1541
1552
|
|
1542
|
-
# See ActionDispatch::Routing::Mapper::Scoping#namespace
|
1553
|
+
# See ActionDispatch::Routing::Mapper::Scoping#namespace.
|
1543
1554
|
def namespace(path, options = {})
|
1544
1555
|
if resource_scope?
|
1545
1556
|
nested { super }
|
@@ -1559,7 +1570,7 @@ module ActionDispatch
|
|
1559
1570
|
!parent_resource.singleton? && @scope[:shallow]
|
1560
1571
|
end
|
1561
1572
|
|
1562
|
-
# Matches a
|
1573
|
+
# Matches a URL pattern to one or more routes.
|
1563
1574
|
# For more information, see match[rdoc-ref:Base#match].
|
1564
1575
|
#
|
1565
1576
|
# match 'path' => 'controller#action', via: patch
|
@@ -1850,7 +1861,7 @@ module ActionDispatch
|
|
1850
1861
|
path_types.fetch(String, []).each do |_path|
|
1851
1862
|
route_options = options.dup
|
1852
1863
|
if _path && option_path
|
1853
|
-
raise ArgumentError, "
|
1864
|
+
raise ArgumentError, "Ambiguous route definition. Both :path and the route path were specified as strings."
|
1854
1865
|
end
|
1855
1866
|
to = get_to_from_path(_path, to, route_options[:action])
|
1856
1867
|
decomposed_match(_path, controller, route_options, _path, to, via, formatted, anchor, options_constraints)
|
@@ -2017,7 +2028,7 @@ module ActionDispatch
|
|
2017
2028
|
# concerns :commentable
|
2018
2029
|
# end
|
2019
2030
|
#
|
2020
|
-
#
|
2031
|
+
# Concerns also work in any routes helper that you want to use:
|
2021
2032
|
#
|
2022
2033
|
# namespace :posts do
|
2023
2034
|
# concerns :commentable
|
@@ -2035,7 +2046,7 @@ module ActionDispatch
|
|
2035
2046
|
end
|
2036
2047
|
|
2037
2048
|
module CustomUrls
|
2038
|
-
# Define custom
|
2049
|
+
# Define custom URL helpers that will be added to the application's
|
2039
2050
|
# routes. This allows you to override and/or replace the default behavior
|
2040
2051
|
# of routing helpers, e.g:
|
2041
2052
|
#
|
@@ -2051,37 +2062,37 @@ module ActionDispatch
|
|
2051
2062
|
# { controller: "pages", action: "index", subdomain: "www" }
|
2052
2063
|
# end
|
2053
2064
|
#
|
2054
|
-
# The return value from the block passed to
|
2055
|
-
# arguments for
|
2065
|
+
# The return value from the block passed to +direct+ must be a valid set of
|
2066
|
+
# arguments for +url_for+ which will actually build the URL string. This can
|
2056
2067
|
# be one of the following:
|
2057
2068
|
#
|
2058
|
-
#
|
2059
|
-
#
|
2060
|
-
#
|
2061
|
-
#
|
2062
|
-
#
|
2069
|
+
# * A string, which is treated as a generated URL
|
2070
|
+
# * A hash, e.g. <tt>{ controller: "pages", action: "index" }</tt>
|
2071
|
+
# * An array, which is passed to +polymorphic_url+
|
2072
|
+
# * An Active Model instance
|
2073
|
+
# * An Active Model class
|
2063
2074
|
#
|
2064
|
-
# NOTE: Other
|
2065
|
-
# your custom
|
2075
|
+
# NOTE: Other URL helpers can be called in the block but be careful not to invoke
|
2076
|
+
# your custom URL helper again otherwise it will result in a stack overflow error.
|
2066
2077
|
#
|
2067
2078
|
# You can also specify default options that will be passed through to
|
2068
|
-
# your
|
2079
|
+
# your URL helper definition, e.g:
|
2069
2080
|
#
|
2070
2081
|
# direct :browse, page: 1, size: 10 do |options|
|
2071
2082
|
# [ :products, options.merge(params.permit(:page, :size).to_h.symbolize_keys) ]
|
2072
2083
|
# end
|
2073
2084
|
#
|
2074
|
-
# In this instance the
|
2075
|
-
# block is executed, e.g. generating a
|
2085
|
+
# In this instance the +params+ object comes from the context in which the the
|
2086
|
+
# block is executed, e.g. generating a URL inside a controller action or a view.
|
2076
2087
|
# If the block is executed where there isn't a params object such as this:
|
2077
2088
|
#
|
2078
2089
|
# Rails.application.routes.url_helpers.browse_path
|
2079
2090
|
#
|
2080
|
-
# then it will raise a
|
2081
|
-
# context in which you will use your custom
|
2091
|
+
# then it will raise a +NameError+. Because of this you need to be aware of the
|
2092
|
+
# context in which you will use your custom URL helper when defining it.
|
2082
2093
|
#
|
2083
|
-
# NOTE: The
|
2084
|
-
#
|
2094
|
+
# NOTE: The +direct+ method can't be used inside of a scope block such as
|
2095
|
+
# +namespace+ or +scope+ and will raise an error if it detects that it is.
|
2085
2096
|
def direct(name, options = {}, &block)
|
2086
2097
|
unless @scope.root?
|
2087
2098
|
raise RuntimeError, "The direct method can't be used inside a routes scope block"
|
@@ -2090,9 +2101,9 @@ module ActionDispatch
|
|
2090
2101
|
@set.add_url_helper(name, options, &block)
|
2091
2102
|
end
|
2092
2103
|
|
2093
|
-
# Define custom polymorphic mappings of models to
|
2094
|
-
# behavior of
|
2095
|
-
#
|
2104
|
+
# Define custom polymorphic mappings of models to URLs. This alters the
|
2105
|
+
# behavior of +polymorphic_url+ and consequently the behavior of
|
2106
|
+
# +link_to+ and +form_for+ when passed a model instance, e.g:
|
2096
2107
|
#
|
2097
2108
|
# resource :basket
|
2098
2109
|
#
|
@@ -2100,10 +2111,10 @@ module ActionDispatch
|
|
2100
2111
|
# [:basket]
|
2101
2112
|
# end
|
2102
2113
|
#
|
2103
|
-
# This will now generate "/basket" when a
|
2104
|
-
#
|
2114
|
+
# This will now generate "/basket" when a +Basket+ instance is passed to
|
2115
|
+
# +link_to+ or +form_for+ instead of the standard "/baskets/:id".
|
2105
2116
|
#
|
2106
|
-
# NOTE: This custom behavior only applies to simple polymorphic
|
2117
|
+
# NOTE: This custom behavior only applies to simple polymorphic URLs where
|
2107
2118
|
# a single model instance is passed and not more complicated forms, e.g:
|
2108
2119
|
#
|
2109
2120
|
# # config/routes.rb
|
@@ -2118,8 +2129,8 @@ module ActionDispatch
|
|
2118
2129
|
# link_to "Profile", @current_user
|
2119
2130
|
# link_to "Profile", [:admin, @current_user]
|
2120
2131
|
#
|
2121
|
-
# The first
|
2122
|
-
# the standard polymorphic
|
2132
|
+
# The first +link_to+ will generate "/profile" but the second will generate
|
2133
|
+
# the standard polymorphic URL of "/admin/users/1".
|
2123
2134
|
#
|
2124
2135
|
# You can pass options to a polymorphic mapping - the arity for the block
|
2125
2136
|
# needs to be two as the instance is passed as the first argument, e.g:
|
@@ -2128,12 +2139,12 @@ module ActionDispatch
|
|
2128
2139
|
# [:basket, options]
|
2129
2140
|
# end
|
2130
2141
|
#
|
2131
|
-
# This generates the
|
2132
|
-
# array passed to
|
2133
|
-
# to the
|
2142
|
+
# This generates the URL "/basket#items" because when the last item in an
|
2143
|
+
# array passed to +polymorphic_url+ is a hash then it's treated as options
|
2144
|
+
# to the URL helper that gets called.
|
2134
2145
|
#
|
2135
|
-
# NOTE: The
|
2136
|
-
#
|
2146
|
+
# NOTE: The +resolve+ method can't be used inside of a scope block such as
|
2147
|
+
# +namespace+ or +scope+ and will raise an error if it detects that it is.
|
2137
2148
|
def resolve(*args, &block)
|
2138
2149
|
unless @scope.root?
|
2139
2150
|
raise RuntimeError, "The resolve method can't be used inside a routes scope block"
|