actionpack 7.1.5.1 → 8.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +308 -523
- data/README.rdoc +1 -1
- data/lib/abstract_controller/asset_paths.rb +6 -2
- data/lib/abstract_controller/base.rb +104 -105
- data/lib/abstract_controller/caching/fragments.rb +50 -53
- data/lib/abstract_controller/caching.rb +8 -3
- data/lib/abstract_controller/callbacks.rb +70 -62
- data/lib/abstract_controller/collector.rb +7 -7
- data/lib/abstract_controller/deprecator.rb +2 -0
- data/lib/abstract_controller/error.rb +2 -0
- data/lib/abstract_controller/helpers.rb +71 -84
- data/lib/abstract_controller/logger.rb +4 -1
- data/lib/abstract_controller/railties/routes_helpers.rb +2 -0
- data/lib/abstract_controller/rendering.rb +13 -13
- data/lib/abstract_controller/translation.rb +12 -13
- data/lib/abstract_controller/url_for.rb +8 -6
- data/lib/abstract_controller.rb +2 -0
- data/lib/action_controller/api/api_rendering.rb +2 -0
- data/lib/action_controller/api.rb +76 -72
- data/lib/action_controller/base.rb +199 -126
- data/lib/action_controller/caching.rb +16 -14
- data/lib/action_controller/deprecator.rb +2 -0
- data/lib/action_controller/form_builder.rb +21 -18
- data/lib/action_controller/log_subscriber.rb +23 -2
- data/lib/action_controller/metal/allow_browser.rb +133 -0
- data/lib/action_controller/metal/basic_implicit_render.rb +2 -0
- data/lib/action_controller/metal/conditional_get.rb +217 -175
- data/lib/action_controller/metal/content_security_policy.rb +25 -24
- data/lib/action_controller/metal/cookies.rb +4 -2
- data/lib/action_controller/metal/data_streaming.rb +72 -63
- data/lib/action_controller/metal/default_headers.rb +5 -3
- data/lib/action_controller/metal/etag_with_flash.rb +3 -1
- data/lib/action_controller/metal/etag_with_template_digest.rb +17 -15
- data/lib/action_controller/metal/exceptions.rb +16 -9
- data/lib/action_controller/metal/flash.rb +13 -14
- data/lib/action_controller/metal/head.rb +15 -11
- data/lib/action_controller/metal/helpers.rb +63 -55
- data/lib/action_controller/metal/http_authentication.rb +209 -201
- data/lib/action_controller/metal/implicit_render.rb +17 -15
- data/lib/action_controller/metal/instrumentation.rb +16 -14
- data/lib/action_controller/metal/live.rb +177 -128
- data/lib/action_controller/metal/logging.rb +6 -4
- data/lib/action_controller/metal/mime_responds.rb +151 -142
- data/lib/action_controller/metal/parameter_encoding.rb +34 -32
- data/lib/action_controller/metal/params_wrapper.rb +57 -59
- data/lib/action_controller/metal/permissions_policy.rb +22 -12
- data/lib/action_controller/metal/rate_limiting.rb +92 -0
- data/lib/action_controller/metal/redirecting.rb +213 -94
- data/lib/action_controller/metal/renderers.rb +78 -57
- data/lib/action_controller/metal/rendering.rb +111 -77
- data/lib/action_controller/metal/request_forgery_protection.rb +182 -143
- data/lib/action_controller/metal/rescue.rb +20 -9
- data/lib/action_controller/metal/streaming.rb +118 -195
- data/lib/action_controller/metal/strong_parameters.rb +720 -530
- data/lib/action_controller/metal/testing.rb +2 -0
- data/lib/action_controller/metal/url_for.rb +17 -15
- data/lib/action_controller/metal.rb +86 -60
- data/lib/action_controller/railtie.rb +36 -15
- data/lib/action_controller/railties/helpers.rb +2 -0
- data/lib/action_controller/renderer.rb +41 -36
- data/lib/action_controller/structured_event_subscriber.rb +116 -0
- data/lib/action_controller/template_assertions.rb +4 -2
- data/lib/action_controller/test_case.rb +160 -131
- data/lib/action_controller.rb +5 -1
- data/lib/action_dispatch/constants.rb +8 -0
- data/lib/action_dispatch/deprecator.rb +2 -0
- data/lib/action_dispatch/http/cache.rb +163 -35
- data/lib/action_dispatch/http/content_disposition.rb +2 -0
- data/lib/action_dispatch/http/content_security_policy.rb +54 -39
- data/lib/action_dispatch/http/filter_parameters.rb +14 -8
- data/lib/action_dispatch/http/filter_redirect.rb +22 -1
- data/lib/action_dispatch/http/headers.rb +22 -22
- data/lib/action_dispatch/http/mime_negotiation.rb +89 -41
- data/lib/action_dispatch/http/mime_type.rb +25 -21
- data/lib/action_dispatch/http/mime_types.rb +3 -0
- data/lib/action_dispatch/http/param_builder.rb +187 -0
- data/lib/action_dispatch/http/param_error.rb +26 -0
- data/lib/action_dispatch/http/parameters.rb +14 -12
- data/lib/action_dispatch/http/permissions_policy.rb +25 -36
- data/lib/action_dispatch/http/query_parser.rb +55 -0
- data/lib/action_dispatch/http/rack_cache.rb +2 -0
- data/lib/action_dispatch/http/request.rb +141 -92
- data/lib/action_dispatch/http/response.rb +137 -77
- data/lib/action_dispatch/http/upload.rb +18 -16
- data/lib/action_dispatch/http/url.rb +187 -89
- data/lib/action_dispatch/journey/formatter.rb +21 -9
- data/lib/action_dispatch/journey/gtg/builder.rb +4 -3
- data/lib/action_dispatch/journey/gtg/simulator.rb +34 -11
- data/lib/action_dispatch/journey/gtg/transition_table.rb +47 -53
- data/lib/action_dispatch/journey/nfa/dot.rb +2 -0
- data/lib/action_dispatch/journey/nodes/node.rb +8 -6
- data/lib/action_dispatch/journey/parser.rb +99 -195
- data/lib/action_dispatch/journey/path/pattern.rb +4 -1
- data/lib/action_dispatch/journey/route.rb +54 -38
- data/lib/action_dispatch/journey/router/utils.rb +22 -27
- data/lib/action_dispatch/journey/router.rb +63 -83
- data/lib/action_dispatch/journey/routes.rb +11 -2
- data/lib/action_dispatch/journey/scanner.rb +46 -42
- data/lib/action_dispatch/journey/visitors.rb +57 -23
- data/lib/action_dispatch/journey/visualizer/fsm.js +4 -6
- data/lib/action_dispatch/journey.rb +2 -0
- data/lib/action_dispatch/log_subscriber.rb +7 -1
- data/lib/action_dispatch/middleware/actionable_exceptions.rb +2 -0
- data/lib/action_dispatch/middleware/assume_ssl.rb +8 -5
- data/lib/action_dispatch/middleware/callbacks.rb +3 -1
- data/lib/action_dispatch/middleware/cookies.rb +125 -106
- data/lib/action_dispatch/middleware/debug_exceptions.rb +37 -8
- data/lib/action_dispatch/middleware/debug_locks.rb +15 -13
- data/lib/action_dispatch/middleware/debug_view.rb +13 -5
- data/lib/action_dispatch/middleware/exception_wrapper.rb +18 -23
- data/lib/action_dispatch/middleware/executor.rb +19 -4
- data/lib/action_dispatch/middleware/flash.rb +63 -51
- data/lib/action_dispatch/middleware/host_authorization.rb +17 -15
- data/lib/action_dispatch/middleware/public_exceptions.rb +14 -12
- data/lib/action_dispatch/middleware/reloader.rb +5 -3
- data/lib/action_dispatch/middleware/remote_ip.rb +87 -77
- data/lib/action_dispatch/middleware/request_id.rb +16 -10
- data/lib/action_dispatch/middleware/server_timing.rb +4 -2
- data/lib/action_dispatch/middleware/session/abstract_store.rb +2 -0
- data/lib/action_dispatch/middleware/session/cache_store.rb +30 -8
- data/lib/action_dispatch/middleware/session/cookie_store.rb +27 -26
- data/lib/action_dispatch/middleware/session/mem_cache_store.rb +7 -3
- data/lib/action_dispatch/middleware/show_exceptions.rb +16 -16
- data/lib/action_dispatch/middleware/ssl.rb +53 -40
- data/lib/action_dispatch/middleware/stack.rb +11 -10
- data/lib/action_dispatch/middleware/static.rb +33 -31
- data/lib/action_dispatch/middleware/templates/rescues/_copy_button.html.erb +1 -0
- data/lib/action_dispatch/middleware/templates/rescues/_source.html.erb +3 -5
- data/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb +9 -5
- data/lib/action_dispatch/middleware/templates/rescues/blocked_host.html.erb +1 -0
- data/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb +1 -0
- data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.html.erb +4 -0
- data/lib/action_dispatch/middleware/templates/rescues/invalid_statement.text.erb +3 -0
- data/lib/action_dispatch/middleware/templates/rescues/layout.erb +50 -0
- data/lib/action_dispatch/middleware/templates/rescues/missing_exact_template.html.erb +1 -0
- data/lib/action_dispatch/middleware/templates/rescues/missing_template.html.erb +1 -0
- data/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb +1 -0
- data/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb +1 -0
- data/lib/action_dispatch/middleware/templates/rescues/unknown_action.html.erb +1 -0
- data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +1 -1
- data/lib/action_dispatch/railtie.rb +23 -3
- data/lib/action_dispatch/request/session.rb +24 -21
- data/lib/action_dispatch/request/utils.rb +11 -3
- data/lib/action_dispatch/routing/endpoint.rb +2 -0
- data/lib/action_dispatch/routing/inspector.rb +85 -60
- data/lib/action_dispatch/routing/mapper.rb +1031 -851
- data/lib/action_dispatch/routing/polymorphic_routes.rb +69 -62
- data/lib/action_dispatch/routing/redirection.rb +47 -39
- data/lib/action_dispatch/routing/route_set.rb +79 -56
- data/lib/action_dispatch/routing/routes_proxy.rb +7 -4
- data/lib/action_dispatch/routing/url_for.rb +130 -125
- data/lib/action_dispatch/routing.rb +150 -148
- data/lib/action_dispatch/structured_event_subscriber.rb +20 -0
- data/lib/action_dispatch/system_test_case.rb +91 -81
- data/lib/action_dispatch/system_testing/browser.rb +16 -23
- data/lib/action_dispatch/system_testing/driver.rb +2 -0
- data/lib/action_dispatch/system_testing/server.rb +2 -0
- data/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb +34 -23
- data/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb +2 -0
- data/lib/action_dispatch/testing/assertion_response.rb +9 -7
- data/lib/action_dispatch/testing/assertions/response.rb +52 -25
- data/lib/action_dispatch/testing/assertions/routing.rb +168 -87
- data/lib/action_dispatch/testing/assertions.rb +2 -0
- data/lib/action_dispatch/testing/integration.rb +233 -223
- data/lib/action_dispatch/testing/request_encoder.rb +11 -9
- data/lib/action_dispatch/testing/test_helpers/page_dump_helper.rb +35 -0
- data/lib/action_dispatch/testing/test_process.rb +11 -8
- data/lib/action_dispatch/testing/test_request.rb +3 -1
- data/lib/action_dispatch/testing/test_response.rb +27 -26
- data/lib/action_dispatch.rb +36 -32
- data/lib/action_pack/gem_version.rb +6 -4
- data/lib/action_pack/version.rb +3 -1
- data/lib/action_pack.rb +17 -16
- metadata +36 -32
- data/lib/action_dispatch/journey/parser.y +0 -50
- data/lib/action_dispatch/journey/parser_extras.rb +0 -31
|
@@ -1,248 +1,250 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
# :markup: markdown
|
|
4
|
+
|
|
3
5
|
module ActionDispatch
|
|
4
6
|
# The routing module provides URL rewriting in native Ruby. It's a way to
|
|
5
7
|
# redirect incoming requests to controllers and actions. This replaces
|
|
6
|
-
# mod_rewrite rules. Best of all, Rails'
|
|
7
|
-
# Routes are defined in
|
|
8
|
+
# mod_rewrite rules. Best of all, Rails' Routing works with any web server.
|
|
9
|
+
# Routes are defined in `config/routes.rb`.
|
|
8
10
|
#
|
|
9
11
|
# Think of creating routes as drawing a map for your requests. The map tells
|
|
10
12
|
# them where to go based on some predefined pattern:
|
|
11
13
|
#
|
|
12
|
-
#
|
|
13
|
-
#
|
|
14
|
-
#
|
|
15
|
-
#
|
|
16
|
-
#
|
|
14
|
+
# Rails.application.routes.draw do
|
|
15
|
+
# Pattern 1 tells some request to go to one place
|
|
16
|
+
# Pattern 2 tell them to go to another
|
|
17
|
+
# ...
|
|
18
|
+
# end
|
|
17
19
|
#
|
|
18
20
|
# The following symbols are special:
|
|
19
21
|
#
|
|
20
|
-
#
|
|
21
|
-
#
|
|
22
|
+
# :controller maps to your controller name
|
|
23
|
+
# :action maps to an action with your controllers
|
|
22
24
|
#
|
|
23
|
-
# Other names simply map to a parameter as in the case of
|
|
25
|
+
# Other names simply map to a parameter as in the case of `:id`.
|
|
24
26
|
#
|
|
25
|
-
#
|
|
27
|
+
# ## Resources
|
|
26
28
|
#
|
|
27
|
-
# Resource routing allows you to quickly declare all of the common routes
|
|
28
|
-
#
|
|
29
|
-
#
|
|
30
|
-
#
|
|
29
|
+
# Resource routing allows you to quickly declare all of the common routes for a
|
|
30
|
+
# given resourceful controller. Instead of declaring separate routes for your
|
|
31
|
+
# `index`, `show`, `new`, `edit`, `create`, `update`, and `destroy` actions, a
|
|
32
|
+
# resourceful route declares them in a single line of code:
|
|
31
33
|
#
|
|
32
|
-
#
|
|
34
|
+
# resources :photos
|
|
33
35
|
#
|
|
34
|
-
# Sometimes, you have a resource that clients always look up without
|
|
35
|
-
#
|
|
36
|
-
#
|
|
37
|
-
#
|
|
36
|
+
# Sometimes, you have a resource that clients always look up without referencing
|
|
37
|
+
# an ID. A common example, /profile always shows the profile of the currently
|
|
38
|
+
# logged in user. In this case, you can use a singular resource to map /profile
|
|
39
|
+
# (rather than /profile/:id) to the show action.
|
|
38
40
|
#
|
|
39
|
-
#
|
|
41
|
+
# resource :profile
|
|
40
42
|
#
|
|
41
|
-
# It's common to have resources that are logically children of other
|
|
42
|
-
# resources:
|
|
43
|
+
# It's common to have resources that are logically children of other resources:
|
|
43
44
|
#
|
|
44
|
-
#
|
|
45
|
-
#
|
|
46
|
-
#
|
|
45
|
+
# resources :magazines do
|
|
46
|
+
# resources :ads
|
|
47
|
+
# end
|
|
47
48
|
#
|
|
48
49
|
# You may wish to organize groups of controllers under a namespace. Most
|
|
49
|
-
# commonly, you might group a number of administrative controllers under
|
|
50
|
-
#
|
|
51
|
-
#
|
|
52
|
-
#
|
|
50
|
+
# commonly, you might group a number of administrative controllers under an
|
|
51
|
+
# `admin` namespace. You would place these controllers under the
|
|
52
|
+
# `app/controllers/admin` directory, and you can group them together in your
|
|
53
|
+
# router:
|
|
53
54
|
#
|
|
54
|
-
#
|
|
55
|
-
#
|
|
56
|
-
#
|
|
55
|
+
# namespace "admin" do
|
|
56
|
+
# resources :posts, :comments
|
|
57
|
+
# end
|
|
57
58
|
#
|
|
58
59
|
# Alternatively, you can add prefixes to your path without using a separate
|
|
59
|
-
# directory by using
|
|
60
|
-
#
|
|
60
|
+
# directory by using `scope`. `scope` takes additional options which apply to
|
|
61
|
+
# all enclosed routes.
|
|
61
62
|
#
|
|
62
|
-
#
|
|
63
|
-
#
|
|
64
|
-
#
|
|
63
|
+
# scope path: "/cpanel", as: 'admin' do
|
|
64
|
+
# resources :posts, :comments
|
|
65
|
+
# end
|
|
65
66
|
#
|
|
66
67
|
# For more, see Routing::Mapper::Resources#resources,
|
|
67
68
|
# Routing::Mapper::Scoping#namespace, and Routing::Mapper::Scoping#scope.
|
|
68
69
|
#
|
|
69
|
-
#
|
|
70
|
+
# ## Non-resourceful routes
|
|
70
71
|
#
|
|
71
|
-
# For routes that don't fit the
|
|
72
|
-
# methods
|
|
72
|
+
# For routes that don't fit the `resources` mold, you can use the HTTP helper
|
|
73
|
+
# methods `get`, `post`, `patch`, `put` and `delete`.
|
|
73
74
|
#
|
|
74
|
-
#
|
|
75
|
-
#
|
|
75
|
+
# get 'post/:id', to: 'posts#show'
|
|
76
|
+
# post 'post/:id', to: 'posts#create_comment'
|
|
76
77
|
#
|
|
77
|
-
# Now, if you POST to
|
|
78
|
-
# URL will route to the
|
|
78
|
+
# Now, if you POST to `/posts/:id`, it will route to the `create_comment`
|
|
79
|
+
# action. A GET on the same URL will route to the `show` action.
|
|
79
80
|
#
|
|
80
|
-
# If your route needs to respond to more than one HTTP method (or all methods)
|
|
81
|
-
#
|
|
81
|
+
# If your route needs to respond to more than one HTTP method (or all methods)
|
|
82
|
+
# then using the `:via` option on `match` is preferable.
|
|
82
83
|
#
|
|
83
|
-
#
|
|
84
|
+
# match 'post/:id', to: 'posts#show', via: [:get, :post]
|
|
84
85
|
#
|
|
85
|
-
#
|
|
86
|
+
# ## Named routes
|
|
86
87
|
#
|
|
87
|
-
# Routes can be named by passing an
|
|
88
|
-
#
|
|
89
|
-
#
|
|
88
|
+
# Routes can be named by passing an `:as` option, allowing for easy reference
|
|
89
|
+
# within your source as `name_of_route_url` for the full URL and
|
|
90
|
+
# `name_of_route_path` for the URI path.
|
|
90
91
|
#
|
|
91
92
|
# Example:
|
|
92
93
|
#
|
|
93
|
-
#
|
|
94
|
-
#
|
|
94
|
+
# # In config/routes.rb
|
|
95
|
+
# get '/login', to: 'accounts#login', as: 'login'
|
|
95
96
|
#
|
|
96
|
-
#
|
|
97
|
-
#
|
|
97
|
+
# # With render, redirect_to, tests, etc.
|
|
98
|
+
# redirect_to login_url
|
|
98
99
|
#
|
|
99
100
|
# Arguments can be passed as well.
|
|
100
101
|
#
|
|
101
|
-
#
|
|
102
|
+
# redirect_to show_item_path(id: 25)
|
|
102
103
|
#
|
|
103
|
-
# Use
|
|
104
|
+
# Use `root` as a shorthand to name a route for the root path "/".
|
|
104
105
|
#
|
|
105
|
-
#
|
|
106
|
-
#
|
|
106
|
+
# # In config/routes.rb
|
|
107
|
+
# root to: 'blogs#index'
|
|
107
108
|
#
|
|
108
|
-
#
|
|
109
|
-
#
|
|
109
|
+
# # would recognize http://www.example.com/ as
|
|
110
|
+
# params = { controller: 'blogs', action: 'index' }
|
|
110
111
|
#
|
|
111
|
-
#
|
|
112
|
-
#
|
|
113
|
-
#
|
|
112
|
+
# # and provide these named routes
|
|
113
|
+
# root_url # => 'http://www.example.com/'
|
|
114
|
+
# root_path # => '/'
|
|
114
115
|
#
|
|
115
|
-
# Note: when using
|
|
116
|
-
#
|
|
116
|
+
# Note: when using `controller`, the route is simply named after the method you
|
|
117
|
+
# call on the block parameter rather than map.
|
|
117
118
|
#
|
|
118
|
-
#
|
|
119
|
-
#
|
|
120
|
-
#
|
|
121
|
-
#
|
|
122
|
-
#
|
|
123
|
-
#
|
|
119
|
+
# # In config/routes.rb
|
|
120
|
+
# controller :blog do
|
|
121
|
+
# get 'blog/show' => :list
|
|
122
|
+
# get 'blog/delete' => :delete
|
|
123
|
+
# get 'blog/edit' => :edit
|
|
124
|
+
# end
|
|
124
125
|
#
|
|
125
|
-
#
|
|
126
|
-
#
|
|
126
|
+
# # provides named routes for show, delete, and edit
|
|
127
|
+
# link_to @article.title, blog_show_path(id: @article.id)
|
|
127
128
|
#
|
|
128
|
-
#
|
|
129
|
+
# ## Pretty URLs
|
|
129
130
|
#
|
|
130
131
|
# Routes can generate pretty URLs. For example:
|
|
131
132
|
#
|
|
132
|
-
#
|
|
133
|
-
#
|
|
134
|
-
#
|
|
135
|
-
#
|
|
136
|
-
#
|
|
133
|
+
# get '/articles/:year/:month/:day', to: 'articles#find_by_id', constraints: {
|
|
134
|
+
# year: /\d{4}/,
|
|
135
|
+
# month: /\d{1,2}/,
|
|
136
|
+
# day: /\d{1,2}/
|
|
137
|
+
# }
|
|
137
138
|
#
|
|
138
139
|
# Using the route above, the URL "http://localhost:3000/articles/2005/11/06"
|
|
139
140
|
# maps to
|
|
140
141
|
#
|
|
141
|
-
#
|
|
142
|
+
# params = {year: '2005', month: '11', day: '06'}
|
|
142
143
|
#
|
|
143
|
-
#
|
|
144
|
+
# ## Regular Expressions and parameters
|
|
144
145
|
# You can specify a regular expression to define a format for a parameter.
|
|
145
146
|
#
|
|
146
|
-
#
|
|
147
|
-
#
|
|
148
|
-
#
|
|
149
|
-
#
|
|
150
|
-
#
|
|
147
|
+
# controller 'geocode' do
|
|
148
|
+
# get 'geocode/:postalcode', to: :show, constraints: {
|
|
149
|
+
# postalcode: /\d{5}(-\d{4})?/
|
|
150
|
+
# }
|
|
151
|
+
# end
|
|
151
152
|
#
|
|
152
153
|
# Constraints can include the 'ignorecase' and 'extended syntax' regular
|
|
153
154
|
# expression modifiers:
|
|
154
155
|
#
|
|
155
|
-
#
|
|
156
|
-
#
|
|
157
|
-
#
|
|
158
|
-
#
|
|
159
|
-
#
|
|
160
|
-
#
|
|
161
|
-
#
|
|
162
|
-
#
|
|
163
|
-
#
|
|
164
|
-
#
|
|
165
|
-
#
|
|
166
|
-
#
|
|
167
|
-
#
|
|
168
|
-
#
|
|
156
|
+
# controller 'geocode' do
|
|
157
|
+
# get 'geocode/:postalcode', to: :show, constraints: {
|
|
158
|
+
# postalcode: /hx\d\d\s\d[a-z]{2}/i
|
|
159
|
+
# }
|
|
160
|
+
# end
|
|
161
|
+
#
|
|
162
|
+
# controller 'geocode' do
|
|
163
|
+
# get 'geocode/:postalcode', to: :show, constraints: {
|
|
164
|
+
# postalcode: /# Postalcode format
|
|
165
|
+
# \d{5} #Prefix
|
|
166
|
+
# (-\d{4})? #Suffix
|
|
167
|
+
# /x
|
|
168
|
+
# }
|
|
169
|
+
# end
|
|
169
170
|
#
|
|
170
|
-
# Using the multiline modifier will raise an
|
|
171
|
-
#
|
|
172
|
-
#
|
|
171
|
+
# Using the multiline modifier will raise an `ArgumentError`. Encoding regular
|
|
172
|
+
# expression modifiers are silently ignored. The match will always use the
|
|
173
|
+
# default encoding or ASCII.
|
|
173
174
|
#
|
|
174
|
-
#
|
|
175
|
+
# ## External redirects
|
|
175
176
|
#
|
|
176
|
-
# You can redirect any path to another path using the redirect helper in your
|
|
177
|
+
# You can redirect any path to another path using the redirect helper in your
|
|
178
|
+
# router:
|
|
177
179
|
#
|
|
178
|
-
#
|
|
180
|
+
# get "/stories", to: redirect("/posts")
|
|
179
181
|
#
|
|
180
|
-
#
|
|
182
|
+
# ## Unicode character routes
|
|
181
183
|
#
|
|
182
184
|
# You can specify unicode character routes in your router:
|
|
183
185
|
#
|
|
184
|
-
#
|
|
186
|
+
# get "こんにちは", to: "welcome#index"
|
|
185
187
|
#
|
|
186
|
-
#
|
|
188
|
+
# ## Routing to Rack Applications
|
|
187
189
|
#
|
|
188
|
-
# Instead of a String, like
|
|
189
|
-
#
|
|
190
|
-
#
|
|
190
|
+
# Instead of a String, like `posts#index`, which corresponds to the index action
|
|
191
|
+
# in the PostsController, you can specify any Rack application as the endpoint
|
|
192
|
+
# for a matcher:
|
|
191
193
|
#
|
|
192
|
-
#
|
|
194
|
+
# get "/application.js", to: Sprockets
|
|
193
195
|
#
|
|
194
|
-
#
|
|
196
|
+
# ## Reloading routes
|
|
195
197
|
#
|
|
196
198
|
# You can reload routes if you feel you must:
|
|
197
199
|
#
|
|
198
|
-
#
|
|
200
|
+
# Rails.application.reload_routes!
|
|
199
201
|
#
|
|
200
|
-
# This will clear all named routes and reload config/routes.rb if the file has
|
|
201
|
-
# last load. To absolutely force reloading, use
|
|
202
|
+
# This will clear all named routes and reload config/routes.rb if the file has
|
|
203
|
+
# been modified from last load. To absolutely force reloading, use `reload!`.
|
|
202
204
|
#
|
|
203
|
-
#
|
|
205
|
+
# ## Testing Routes
|
|
204
206
|
#
|
|
205
207
|
# The two main methods for testing your routes:
|
|
206
208
|
#
|
|
207
|
-
#
|
|
209
|
+
# ### `assert_routing`
|
|
208
210
|
#
|
|
209
|
-
#
|
|
210
|
-
#
|
|
211
|
-
#
|
|
212
|
-
#
|
|
211
|
+
# def test_movie_route_properly_splits
|
|
212
|
+
# opts = {controller: "plugin", action: "checkout", id: "2"}
|
|
213
|
+
# assert_routing "plugin/checkout/2", opts
|
|
214
|
+
# end
|
|
213
215
|
#
|
|
214
|
-
#
|
|
216
|
+
# `assert_routing` lets you test whether or not the route properly resolves into
|
|
217
|
+
# options.
|
|
215
218
|
#
|
|
216
|
-
#
|
|
219
|
+
# ### `assert_recognizes`
|
|
217
220
|
#
|
|
218
|
-
#
|
|
219
|
-
#
|
|
220
|
-
#
|
|
221
|
-
#
|
|
221
|
+
# def test_route_has_options
|
|
222
|
+
# opts = {controller: "plugin", action: "show", id: "12"}
|
|
223
|
+
# assert_recognizes opts, "/plugins/show/12"
|
|
224
|
+
# end
|
|
222
225
|
#
|
|
223
|
-
# Note the subtle difference between the two:
|
|
224
|
-
#
|
|
225
|
-
#
|
|
226
|
+
# Note the subtle difference between the two: `assert_routing` tests that a URL
|
|
227
|
+
# fits options while `assert_recognizes` tests that a URL breaks into parameters
|
|
228
|
+
# properly.
|
|
226
229
|
#
|
|
227
|
-
# In tests you can simply pass the URL or named route to
|
|
230
|
+
# In tests you can simply pass the URL or named route to `get` or `post`.
|
|
228
231
|
#
|
|
229
|
-
#
|
|
230
|
-
#
|
|
231
|
-
#
|
|
232
|
-
#
|
|
232
|
+
# def send_to_jail
|
|
233
|
+
# get '/jail'
|
|
234
|
+
# assert_response :success
|
|
235
|
+
# end
|
|
233
236
|
#
|
|
234
|
-
#
|
|
235
|
-
#
|
|
236
|
-
#
|
|
237
|
-
#
|
|
237
|
+
# def goes_to_login
|
|
238
|
+
# get login_url
|
|
239
|
+
# #...
|
|
240
|
+
# end
|
|
238
241
|
#
|
|
239
|
-
#
|
|
242
|
+
# ## View a list of all your routes
|
|
240
243
|
#
|
|
241
|
-
#
|
|
244
|
+
# $ bin/rails routes
|
|
242
245
|
#
|
|
243
|
-
# Target a specific controller with
|
|
244
|
-
#
|
|
245
|
-
# which displays routes vertically.
|
|
246
|
+
# Target a specific controller with `-c`, or grep routes using `-g`. Useful in
|
|
247
|
+
# conjunction with `--expanded` which displays routes vertically.
|
|
246
248
|
module Routing
|
|
247
249
|
extend ActiveSupport::Autoload
|
|
248
250
|
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ActionDispatch
|
|
4
|
+
class StructuredEventSubscriber < ActiveSupport::StructuredEventSubscriber # :nodoc:
|
|
5
|
+
def redirect(event)
|
|
6
|
+
payload = event.payload
|
|
7
|
+
status = payload[:status]
|
|
8
|
+
|
|
9
|
+
emit_event("action_dispatch.redirect", {
|
|
10
|
+
location: payload[:location],
|
|
11
|
+
status: status,
|
|
12
|
+
status_name: Rack::Utils::HTTP_STATUS_CODES[status],
|
|
13
|
+
duration_ms: event.duration.round(2),
|
|
14
|
+
source_location: payload[:source_location]
|
|
15
|
+
})
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
ActionDispatch::StructuredEventSubscriber.attach_to :action_dispatch
|