actionpack 3.2.22.5 → 5.2.4
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 +279 -603
- data/MIT-LICENSE +1 -1
- data/README.rdoc +13 -297
- data/lib/abstract_controller/asset_paths.rb +4 -2
- data/lib/abstract_controller/base.rb +82 -52
- data/lib/abstract_controller/caching/fragments.rb +166 -0
- data/lib/abstract_controller/caching.rb +66 -0
- data/lib/abstract_controller/callbacks.rb +117 -103
- data/lib/abstract_controller/collector.rb +18 -7
- data/lib/abstract_controller/error.rb +6 -0
- data/lib/abstract_controller/helpers.rb +65 -38
- data/lib/abstract_controller/logger.rb +3 -2
- data/lib/abstract_controller/railties/routes_helpers.rb +5 -3
- data/lib/abstract_controller/rendering.rb +77 -129
- data/lib/abstract_controller/translation.rb +21 -3
- data/lib/abstract_controller/url_for.rb +9 -7
- data/lib/abstract_controller.rb +12 -13
- data/lib/action_controller/api/api_rendering.rb +16 -0
- data/lib/action_controller/api.rb +149 -0
- data/lib/action_controller/base.rb +81 -40
- data/lib/action_controller/caching.rb +22 -62
- data/lib/action_controller/form_builder.rb +50 -0
- data/lib/action_controller/log_subscriber.rb +30 -18
- data/lib/action_controller/metal/basic_implicit_render.rb +13 -0
- data/lib/action_controller/metal/conditional_get.rb +190 -47
- 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 +40 -65
- data/lib/action_controller/metal/etag_with_flash.rb +18 -0
- data/lib/action_controller/metal/etag_with_template_digest.rb +57 -0
- data/lib/action_controller/metal/exceptions.rb +19 -12
- data/lib/action_controller/metal/flash.rb +42 -9
- data/lib/action_controller/metal/force_ssl.rb +79 -19
- data/lib/action_controller/metal/head.rb +35 -10
- data/lib/action_controller/metal/helpers.rb +31 -21
- data/lib/action_controller/metal/http_authentication.rb +182 -134
- data/lib/action_controller/metal/implicit_render.rb +62 -8
- data/lib/action_controller/metal/instrumentation.rb +28 -26
- data/lib/action_controller/metal/live.rb +312 -0
- data/lib/action_controller/metal/mime_responds.rb +159 -163
- data/lib/action_controller/metal/parameter_encoding.rb +51 -0
- data/lib/action_controller/metal/params_wrapper.rb +146 -93
- data/lib/action_controller/metal/redirecting.rb +80 -56
- data/lib/action_controller/metal/renderers.rb +119 -47
- data/lib/action_controller/metal/rendering.rb +89 -32
- data/lib/action_controller/metal/request_forgery_protection.rb +373 -41
- data/lib/action_controller/metal/rescue.rb +9 -16
- data/lib/action_controller/metal/streaming.rb +39 -45
- data/lib/action_controller/metal/strong_parameters.rb +1086 -0
- data/lib/action_controller/metal/testing.rb +8 -29
- data/lib/action_controller/metal/url_for.rb +43 -32
- data/lib/action_controller/metal.rb +112 -106
- data/lib/action_controller/railtie.rb +56 -18
- data/lib/action_controller/railties/helpers.rb +24 -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 +402 -347
- data/lib/action_controller.rb +31 -30
- data/lib/action_dispatch/http/cache.rb +133 -34
- data/lib/action_dispatch/http/content_security_policy.rb +272 -0
- data/lib/action_dispatch/http/filter_parameters.rb +40 -24
- data/lib/action_dispatch/http/filter_redirect.rb +37 -0
- data/lib/action_dispatch/http/headers.rb +117 -16
- data/lib/action_dispatch/http/mime_negotiation.rb +98 -33
- data/lib/action_dispatch/http/mime_type.rb +198 -146
- data/lib/action_dispatch/http/mime_types.rb +22 -7
- data/lib/action_dispatch/http/parameter_filter.rb +61 -49
- data/lib/action_dispatch/http/parameters.rb +94 -51
- data/lib/action_dispatch/http/rack_cache.rb +4 -3
- data/lib/action_dispatch/http/request.rb +262 -117
- data/lib/action_dispatch/http/response.rb +400 -86
- data/lib/action_dispatch/http/upload.rb +66 -29
- data/lib/action_dispatch/http/url.rb +232 -60
- data/lib/action_dispatch/journey/formatter.rb +189 -0
- data/lib/action_dispatch/journey/gtg/builder.rb +164 -0
- data/lib/action_dispatch/journey/gtg/simulator.rb +41 -0
- data/lib/action_dispatch/journey/gtg/transition_table.rb +158 -0
- data/lib/action_dispatch/journey/nfa/builder.rb +78 -0
- data/lib/action_dispatch/journey/nfa/dot.rb +36 -0
- data/lib/action_dispatch/journey/nfa/simulator.rb +49 -0
- data/lib/action_dispatch/journey/nfa/transition_table.rb +120 -0
- data/lib/action_dispatch/journey/nodes/node.rb +140 -0
- data/lib/action_dispatch/journey/parser.rb +199 -0
- data/lib/action_dispatch/journey/parser.y +50 -0
- data/lib/action_dispatch/journey/parser_extras.rb +31 -0
- data/lib/action_dispatch/journey/path/pattern.rb +199 -0
- data/lib/action_dispatch/journey/route.rb +203 -0
- data/lib/action_dispatch/journey/router/utils.rb +102 -0
- data/lib/action_dispatch/journey/router.rb +156 -0
- data/lib/action_dispatch/journey/routes.rb +82 -0
- data/lib/action_dispatch/journey/scanner.rb +64 -0
- data/lib/action_dispatch/journey/visitors.rb +268 -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 +7 -0
- data/lib/action_dispatch/middleware/callbacks.rb +17 -13
- data/lib/action_dispatch/middleware/cookies.rb +494 -162
- data/lib/action_dispatch/middleware/debug_exceptions.rb +176 -53
- data/lib/action_dispatch/middleware/debug_locks.rb +124 -0
- data/lib/action_dispatch/middleware/exception_wrapper.rb +103 -38
- data/lib/action_dispatch/middleware/executor.rb +21 -0
- data/lib/action_dispatch/middleware/flash.rb +128 -91
- data/lib/action_dispatch/middleware/public_exceptions.rb +43 -16
- data/lib/action_dispatch/middleware/reloader.rb +6 -83
- data/lib/action_dispatch/middleware/remote_ip.rb +151 -49
- data/lib/action_dispatch/middleware/request_id.rb +19 -15
- data/lib/action_dispatch/middleware/session/abstract_store.rb +38 -34
- data/lib/action_dispatch/middleware/session/cache_store.rb +14 -9
- data/lib/action_dispatch/middleware/session/cookie_store.rb +94 -44
- data/lib/action_dispatch/middleware/session/mem_cache_store.rb +15 -4
- data/lib/action_dispatch/middleware/show_exceptions.rb +36 -61
- data/lib/action_dispatch/middleware/ssl.rb +150 -0
- data/lib/action_dispatch/middleware/stack.rb +33 -41
- data/lib/action_dispatch/middleware/static.rb +92 -48
- data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb +22 -0
- data/lib/action_dispatch/middleware/templates/rescues/_request_and_response.text.erb +23 -0
- data/lib/action_dispatch/middleware/templates/rescues/_source.html.erb +27 -0
- data/lib/action_dispatch/middleware/templates/rescues/_source.text.erb +8 -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/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 +134 -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 +29 -8
- data/lib/action_dispatch/request/session.rb +234 -0
- data/lib/action_dispatch/request/utils.rb +78 -0
- data/lib/action_dispatch/routing/endpoint.rb +17 -0
- data/lib/action_dispatch/routing/inspector.rb +225 -0
- data/lib/action_dispatch/routing/mapper.rb +1329 -582
- data/lib/action_dispatch/routing/polymorphic_routes.rb +237 -94
- data/lib/action_dispatch/routing/redirection.rb +120 -50
- data/lib/action_dispatch/routing/route_set.rb +545 -322
- data/lib/action_dispatch/routing/routes_proxy.rb +37 -7
- data/lib/action_dispatch/routing/url_for.rb +103 -34
- data/lib/action_dispatch/routing.rb +66 -99
- 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/response.rb +53 -42
- data/lib/action_dispatch/testing/assertions/routing.rb +79 -74
- data/lib/action_dispatch/testing/assertions.rb +15 -9
- data/lib/action_dispatch/testing/integration.rb +361 -207
- data/lib/action_dispatch/testing/request_encoder.rb +55 -0
- data/lib/action_dispatch/testing/test_process.rb +28 -19
- data/lib/action_dispatch/testing/test_request.rb +30 -33
- data/lib/action_dispatch/testing/test_response.rb +35 -11
- data/lib/action_dispatch.rb +42 -32
- data/lib/action_pack/gem_version.rb +17 -0
- data/lib/action_pack/version.rb +7 -7
- data/lib/action_pack.rb +4 -2
- metadata +116 -175
- 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/fragments.rb +0 -127
- 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/hide_actions.rb +0 -41
- data/lib/action_controller/metal/rack_delegation.rb +0 -26
- data/lib/action_controller/metal/responder.rb +0 -286
- data/lib/action_controller/metal/session_management.rb +0 -14
- data/lib/action_controller/middleware.rb +0 -39
- 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/params_parser.rb +0 -75
- 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/assertions/dom.rb +0 -37
- data/lib/action_dispatch/testing/assertions/selector.rb +0 -435
- data/lib/action_dispatch/testing/assertions/tag.rb +0 -138
- 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 -92
- data/lib/action_view/helpers/sanitize_helper.rb +0 -259
- data/lib/action_view/helpers/tag_helper.rb +0 -167
- 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 -258
- data/lib/action_view/path_set.rb +0 -101
- 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 -61
- data/lib/action_view/renderer/streaming_template_renderer.rb +0 -106
- data/lib/action_view/renderer/template_renderer.rb +0 -95
- 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 -298
- 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 -246
- data/lib/action_view/testing/resolvers.rb +0 -49
- 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,3 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/core_ext/array/extract_options"
|
4
|
+
|
1
5
|
module ActionDispatch
|
2
6
|
module Routing
|
3
7
|
class RoutesProxy #:nodoc:
|
@@ -6,8 +10,10 @@ module ActionDispatch
|
|
6
10
|
attr_accessor :scope, :routes
|
7
11
|
alias :_routes :routes
|
8
12
|
|
9
|
-
def initialize(routes, scope)
|
13
|
+
def initialize(routes, scope, helpers, script_namer = nil)
|
10
14
|
@routes, @scope = routes, scope
|
15
|
+
@helpers = helpers
|
16
|
+
@script_namer = script_namer
|
11
17
|
end
|
12
18
|
|
13
19
|
def url_options
|
@@ -16,24 +22,48 @@ module ActionDispatch
|
|
16
22
|
end
|
17
23
|
end
|
18
24
|
|
19
|
-
|
20
|
-
|
25
|
+
private
|
26
|
+
def respond_to_missing?(method, _)
|
27
|
+
super || @helpers.respond_to?(method)
|
21
28
|
end
|
22
29
|
|
23
30
|
def method_missing(method, *args)
|
24
|
-
if
|
31
|
+
if @helpers.respond_to?(method)
|
25
32
|
self.class.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
26
33
|
def #{method}(*args)
|
27
34
|
options = args.extract_options!
|
28
|
-
|
29
|
-
|
35
|
+
options = url_options.merge((options || {}).symbolize_keys)
|
36
|
+
|
37
|
+
if @script_namer
|
38
|
+
options[:script_name] = merge_script_names(
|
39
|
+
options[:script_name],
|
40
|
+
@script_namer.call(options)
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
args << options
|
45
|
+
@helpers.#{method}(*args)
|
30
46
|
end
|
31
47
|
RUBY
|
32
|
-
|
48
|
+
public_send(method, *args)
|
33
49
|
else
|
34
50
|
super
|
35
51
|
end
|
36
52
|
end
|
53
|
+
|
54
|
+
# Keeps the part of the script name provided by the global
|
55
|
+
# context via ENV["SCRIPT_NAME"], which `mount` doesn't know
|
56
|
+
# about since it depends on the specific request, but use our
|
57
|
+
# script name resolver for the mount point dependent part.
|
58
|
+
def merge_script_names(previous_script_name, new_script_name)
|
59
|
+
return new_script_name unless previous_script_name
|
60
|
+
|
61
|
+
resolved_parts = new_script_name.count("/")
|
62
|
+
previous_parts = previous_script_name.count("/")
|
63
|
+
context_parts = previous_parts - resolved_parts + 1
|
64
|
+
|
65
|
+
(previous_script_name.split("/").slice(0, context_parts).join("/")) + new_script_name
|
66
|
+
end
|
37
67
|
end
|
38
68
|
end
|
39
69
|
end
|
@@ -1,14 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActionDispatch
|
2
4
|
module Routing
|
3
5
|
# In <tt>config/routes.rb</tt> you define URL-to-controller mappings, but the reverse
|
4
|
-
# is also possible:
|
6
|
+
# is also possible: a URL can be generated from one of your routing definitions.
|
5
7
|
# URL generation functionality is centralized in this module.
|
6
8
|
#
|
7
9
|
# See ActionDispatch::Routing for general information about routing and routes.rb.
|
8
10
|
#
|
9
11
|
# <b>Tip:</b> If you need to generate URLs from your models or some other place,
|
10
12
|
# then ActionController::UrlFor is what you're looking for. Read on for
|
11
|
-
# an introduction.
|
13
|
+
# an introduction. In general, this module should not be included on its own,
|
14
|
+
# as it is usually included by url_helpers (as in Rails.application.routes.url_helpers).
|
12
15
|
#
|
13
16
|
# == URL generation from parameters
|
14
17
|
#
|
@@ -17,9 +20,9 @@ module ActionDispatch
|
|
17
20
|
# of parameters. For example, you've probably had the chance to write code
|
18
21
|
# like this in one of your views:
|
19
22
|
#
|
20
|
-
# <%= link_to('Click here', :
|
21
|
-
# :
|
22
|
-
# # => "/users/new?message=Welcome%21"
|
23
|
+
# <%= link_to('Click here', controller: 'users',
|
24
|
+
# action: 'new', message: 'Welcome!') %>
|
25
|
+
# # => <a href="/users/new?message=Welcome%21">Click here</a>
|
23
26
|
#
|
24
27
|
# link_to, and all other functions that require URL generation functionality,
|
25
28
|
# actually use ActionController::UrlFor under the hood. And in particular,
|
@@ -27,22 +30,22 @@ module ActionDispatch
|
|
27
30
|
# the same path as the above example by using the following code:
|
28
31
|
#
|
29
32
|
# include UrlFor
|
30
|
-
# url_for(:
|
31
|
-
# :
|
32
|
-
# :
|
33
|
-
# :
|
33
|
+
# url_for(controller: 'users',
|
34
|
+
# action: 'new',
|
35
|
+
# message: 'Welcome!',
|
36
|
+
# only_path: true)
|
34
37
|
# # => "/users/new?message=Welcome%21"
|
35
38
|
#
|
36
|
-
# Notice the <tt
|
39
|
+
# Notice the <tt>only_path: true</tt> part. This is because UrlFor has no
|
37
40
|
# information about the website hostname that your Rails app is serving. So if you
|
38
41
|
# want to include the hostname as well, then you must also pass the <tt>:host</tt>
|
39
42
|
# argument:
|
40
43
|
#
|
41
44
|
# include UrlFor
|
42
|
-
# url_for(:
|
43
|
-
# :
|
44
|
-
# :
|
45
|
-
# :
|
45
|
+
# url_for(controller: 'users',
|
46
|
+
# action: 'new',
|
47
|
+
# message: 'Welcome!',
|
48
|
+
# host: 'www.example.com')
|
46
49
|
# # => "http://www.example.com/users/new?message=Welcome%21"
|
47
50
|
#
|
48
51
|
# By default, all controllers and views have access to a special version of url_for,
|
@@ -51,9 +54,11 @@ module ActionDispatch
|
|
51
54
|
# argument.
|
52
55
|
#
|
53
56
|
# For convenience reasons, mailers provide a shortcut for ActionController::UrlFor#url_for.
|
54
|
-
# So within mailers, you only have to type
|
55
|
-
# in full. However, mailers don't have hostname information, and
|
56
|
-
#
|
57
|
+
# So within mailers, you only have to type +url_for+ instead of 'ActionController::UrlFor#url_for'
|
58
|
+
# in full. However, mailers don't have hostname information, and you still have to provide
|
59
|
+
# the +:host+ argument or set the default host that will be used in all mailers using the
|
60
|
+
# configuration option +config.action_mailer.default_url_options+. For more information on
|
61
|
+
# url_for in mailers read the ActionMailer#Base documentation.
|
57
62
|
#
|
58
63
|
#
|
59
64
|
# == URL generation for named routes
|
@@ -67,7 +72,7 @@ module ActionDispatch
|
|
67
72
|
# This generates, among other things, the method <tt>users_path</tt>. By default,
|
68
73
|
# this method is accessible from your controllers, views and mailers. If you need
|
69
74
|
# to access this auto-generated method from other places (such as a model), then
|
70
|
-
# you can do that by including
|
75
|
+
# you can do that by including Rails.application.routes.url_helpers in your class:
|
71
76
|
#
|
72
77
|
# class User < ActiveRecord::Base
|
73
78
|
# include Rails.application.routes.url_helpers
|
@@ -84,18 +89,18 @@ module ActionDispatch
|
|
84
89
|
include PolymorphicRoutes
|
85
90
|
|
86
91
|
included do
|
87
|
-
# TODO: with_routing extends @controller with url_helpers, trickling down to including this module which overrides its default_url_options
|
88
92
|
unless method_defined?(:default_url_options)
|
89
93
|
# Including in a class uses an inheritable hash. Modules get a plain hash.
|
90
94
|
if respond_to?(:class_attribute)
|
91
95
|
class_attribute :default_url_options
|
92
96
|
else
|
93
|
-
|
94
|
-
remove_method :default_url_options
|
97
|
+
mattr_writer :default_url_options
|
95
98
|
end
|
96
99
|
|
97
100
|
self.default_url_options = {}
|
98
101
|
end
|
102
|
+
|
103
|
+
include(*_url_for_modules) if respond_to?(:_url_for_modules)
|
99
104
|
end
|
100
105
|
|
101
106
|
def initialize(*)
|
@@ -103,14 +108,17 @@ module ActionDispatch
|
|
103
108
|
super
|
104
109
|
end
|
105
110
|
|
111
|
+
# Hook overridden in controller to add request information
|
112
|
+
# with +default_url_options+. Application logic should not
|
113
|
+
# go into url_options.
|
106
114
|
def url_options
|
107
115
|
default_url_options
|
108
116
|
end
|
109
117
|
|
110
|
-
# Generate a
|
118
|
+
# Generate a URL based on the options provided, default_url_options and the
|
111
119
|
# routes defined in routes.rb. The following options are supported:
|
112
120
|
#
|
113
|
-
# * <tt>:only_path</tt> - If true, the relative
|
121
|
+
# * <tt>:only_path</tt> - If true, the relative URL is returned. Defaults to +false+.
|
114
122
|
# * <tt>:protocol</tt> - The protocol to connect to. Defaults to 'http'.
|
115
123
|
# * <tt>:host</tt> - Specifies the host the link should be targeted at.
|
116
124
|
# If <tt>:only_path</tt> is false, this option must be
|
@@ -126,40 +134,101 @@ module ActionDispatch
|
|
126
134
|
# * <tt>:port</tt> - Optionally specify the port to connect to.
|
127
135
|
# * <tt>:anchor</tt> - An anchor name to be appended to the path.
|
128
136
|
# * <tt>:trailing_slash</tt> - If true, adds a trailing slash, as in "/archive/2009/"
|
137
|
+
# * <tt>:script_name</tt> - Specifies application path relative to domain root. If provided, prepends application path.
|
129
138
|
#
|
130
139
|
# Any other key (<tt>:controller</tt>, <tt>:action</tt>, etc.) given to
|
131
140
|
# +url_for+ is forwarded to the Routes module.
|
132
141
|
#
|
133
|
-
#
|
134
|
-
#
|
135
|
-
# url_for :controller => 'tasks', :action => 'testing', :host => 'somehost.org', :port => '8080'
|
142
|
+
# url_for controller: 'tasks', action: 'testing', host: 'somehost.org', port: '8080'
|
136
143
|
# # => 'http://somehost.org:8080/tasks/testing'
|
137
|
-
# url_for :
|
144
|
+
# url_for controller: 'tasks', action: 'testing', host: 'somehost.org', anchor: 'ok', only_path: true
|
138
145
|
# # => '/tasks/testing#ok'
|
139
|
-
# url_for :
|
146
|
+
# url_for controller: 'tasks', action: 'testing', trailing_slash: true
|
140
147
|
# # => 'http://somehost.org/tasks/testing/'
|
141
|
-
# url_for :
|
148
|
+
# url_for controller: 'tasks', action: 'testing', host: 'somehost.org', number: '33'
|
142
149
|
# # => 'http://somehost.org/tasks/testing?number=33'
|
150
|
+
# url_for controller: 'tasks', action: 'testing', host: 'somehost.org', script_name: "/myapp"
|
151
|
+
# # => 'http://somehost.org/myapp/tasks/testing'
|
152
|
+
# url_for controller: 'tasks', action: 'testing', host: 'somehost.org', script_name: "/myapp", only_path: true
|
153
|
+
# # => '/myapp/tasks/testing'
|
154
|
+
#
|
155
|
+
# Missing routes keys may be filled in from the current request's parameters
|
156
|
+
# (e.g. +:controller+, +:action+, +:id+ and any other parameters that are
|
157
|
+
# placed in the path). Given that the current action has been reached
|
158
|
+
# through <tt>GET /users/1</tt>:
|
159
|
+
#
|
160
|
+
# url_for(only_path: true) # => '/users/1'
|
161
|
+
# url_for(only_path: true, action: 'edit') # => '/users/1/edit'
|
162
|
+
# url_for(only_path: true, action: 'edit', id: 2) # => '/users/2/edit'
|
163
|
+
#
|
164
|
+
# Notice that no +:id+ parameter was provided to the first +url_for+ call
|
165
|
+
# and the helper used the one from the route's path. Any path parameter
|
166
|
+
# implicitly used by +url_for+ can always be overwritten like shown on the
|
167
|
+
# last +url_for+ calls.
|
143
168
|
def url_for(options = nil)
|
169
|
+
full_url_for(options)
|
170
|
+
end
|
171
|
+
|
172
|
+
def full_url_for(options = nil) # :nodoc:
|
144
173
|
case options
|
174
|
+
when nil
|
175
|
+
_routes.url_for(url_options.symbolize_keys)
|
176
|
+
when Hash, ActionController::Parameters
|
177
|
+
route_name = options.delete :use_route
|
178
|
+
merged_url_options = options.to_h.symbolize_keys.reverse_merge!(url_options)
|
179
|
+
_routes.url_for(merged_url_options, route_name)
|
145
180
|
when String
|
146
181
|
options
|
147
|
-
when
|
148
|
-
|
182
|
+
when Symbol
|
183
|
+
HelperMethodBuilder.url.handle_string_call self, options
|
184
|
+
when Array
|
185
|
+
components = options.dup
|
186
|
+
polymorphic_url(components, components.extract_options!)
|
187
|
+
when Class
|
188
|
+
HelperMethodBuilder.url.handle_class_call self, options
|
149
189
|
else
|
150
|
-
|
190
|
+
HelperMethodBuilder.url.handle_model_call self, options
|
151
191
|
end
|
152
192
|
end
|
153
193
|
|
194
|
+
# Allows calling direct or regular named route.
|
195
|
+
#
|
196
|
+
# resources :buckets
|
197
|
+
#
|
198
|
+
# direct :recordable do |recording|
|
199
|
+
# route_for(:bucket, recording.bucket)
|
200
|
+
# end
|
201
|
+
#
|
202
|
+
# direct :threadable do |threadable|
|
203
|
+
# route_for(:recordable, threadable.parent)
|
204
|
+
# end
|
205
|
+
#
|
206
|
+
# This maintains the context of the original caller on
|
207
|
+
# whether to return a path or full URL, e.g:
|
208
|
+
#
|
209
|
+
# threadable_path(threadable) # => "/buckets/1"
|
210
|
+
# threadable_url(threadable) # => "http://example.com/buckets/1"
|
211
|
+
#
|
212
|
+
def route_for(name, *args)
|
213
|
+
public_send(:"#{name}_url", *args)
|
214
|
+
end
|
215
|
+
|
154
216
|
protected
|
155
|
-
|
217
|
+
|
218
|
+
def optimize_routes_generation?
|
219
|
+
_routes.optimize_routes_generation? && default_url_options.empty?
|
220
|
+
end
|
221
|
+
|
222
|
+
private
|
223
|
+
|
224
|
+
def _with_routes(routes) # :doc:
|
156
225
|
old_routes, @_routes = @_routes, routes
|
157
226
|
yield
|
158
227
|
ensure
|
159
228
|
@_routes = old_routes
|
160
229
|
end
|
161
230
|
|
162
|
-
def _routes_context
|
231
|
+
def _routes_context # :doc:
|
163
232
|
self
|
164
233
|
end
|
165
234
|
end
|
@@ -1,5 +1,6 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/core_ext/string/filters"
|
3
4
|
|
4
5
|
module ActionDispatch
|
5
6
|
# The routing module provides URL rewriting in native Ruby. It's a way to
|
@@ -10,7 +11,7 @@ module ActionDispatch
|
|
10
11
|
# Think of creating routes as drawing a map for your requests. The map tells
|
11
12
|
# them where to go based on some predefined pattern:
|
12
13
|
#
|
13
|
-
#
|
14
|
+
# Rails.application.routes.draw do
|
14
15
|
# Pattern 1 tells some request to go to one place
|
15
16
|
# Pattern 2 tell them to go to another
|
16
17
|
# ...
|
@@ -56,11 +57,11 @@ module ActionDispatch
|
|
56
57
|
# resources :posts, :comments
|
57
58
|
# end
|
58
59
|
#
|
59
|
-
#
|
60
|
+
# Alternatively, you can add prefixes to your path without using a separate
|
60
61
|
# directory by using +scope+. +scope+ takes additional options which
|
61
62
|
# apply to all enclosed routes.
|
62
63
|
#
|
63
|
-
# scope :
|
64
|
+
# scope path: "/cpanel", as: 'admin' do
|
64
65
|
# resources :posts, :comments
|
65
66
|
# end
|
66
67
|
#
|
@@ -68,6 +69,22 @@ module ActionDispatch
|
|
68
69
|
# <tt>Routing::Mapper::Scoping#namespace</tt>, and
|
69
70
|
# <tt>Routing::Mapper::Scoping#scope</tt>.
|
70
71
|
#
|
72
|
+
# == Non-resourceful routes
|
73
|
+
#
|
74
|
+
# For routes that don't fit the <tt>resources</tt> mold, you can use the HTTP helper
|
75
|
+
# methods <tt>get</tt>, <tt>post</tt>, <tt>patch</tt>, <tt>put</tt> and <tt>delete</tt>.
|
76
|
+
#
|
77
|
+
# get 'post/:id' => 'posts#show'
|
78
|
+
# post 'post/:id' => 'posts#create_comment'
|
79
|
+
#
|
80
|
+
# Now, if you POST to <tt>/posts/:id</tt>, it will route to the <tt>create_comment</tt> action. A GET on the same
|
81
|
+
# URL will route to the <tt>show</tt> action.
|
82
|
+
#
|
83
|
+
# If your route needs to respond to more than one HTTP method (or all methods) then using the
|
84
|
+
# <tt>:via</tt> option on <tt>match</tt> is preferable.
|
85
|
+
#
|
86
|
+
# match 'post/:id' => 'posts#show', via: [:get, :post]
|
87
|
+
#
|
71
88
|
# == Named routes
|
72
89
|
#
|
73
90
|
# Routes can be named by passing an <tt>:as</tt> option,
|
@@ -76,23 +93,23 @@ module ActionDispatch
|
|
76
93
|
#
|
77
94
|
# Example:
|
78
95
|
#
|
79
|
-
# # In routes.rb
|
80
|
-
#
|
96
|
+
# # In config/routes.rb
|
97
|
+
# get '/login' => 'accounts#login', as: 'login'
|
81
98
|
#
|
82
99
|
# # With render, redirect_to, tests, etc.
|
83
100
|
# redirect_to login_url
|
84
101
|
#
|
85
102
|
# Arguments can be passed as well.
|
86
103
|
#
|
87
|
-
# redirect_to show_item_path(:
|
104
|
+
# redirect_to show_item_path(id: 25)
|
88
105
|
#
|
89
106
|
# Use <tt>root</tt> as a shorthand to name a route for the root path "/".
|
90
107
|
#
|
91
|
-
# # In routes.rb
|
92
|
-
# root :
|
108
|
+
# # In config/routes.rb
|
109
|
+
# root to: 'blogs#index'
|
93
110
|
#
|
94
111
|
# # would recognize http://www.example.com/ as
|
95
|
-
# params = { :
|
112
|
+
# params = { controller: 'blogs', action: 'index' }
|
96
113
|
#
|
97
114
|
# # and provide these named routes
|
98
115
|
# root_url # => 'http://www.example.com/'
|
@@ -101,119 +118,73 @@ module ActionDispatch
|
|
101
118
|
# Note: when using +controller+, the route is simply named after the
|
102
119
|
# method you call on the block parameter rather than map.
|
103
120
|
#
|
104
|
-
# # In routes.rb
|
121
|
+
# # In config/routes.rb
|
105
122
|
# controller :blog do
|
106
|
-
#
|
107
|
-
#
|
108
|
-
#
|
123
|
+
# get 'blog/show' => :list
|
124
|
+
# get 'blog/delete' => :delete
|
125
|
+
# get 'blog/edit' => :edit
|
109
126
|
# end
|
110
127
|
#
|
111
128
|
# # provides named routes for show, delete, and edit
|
112
|
-
# link_to @article.title,
|
129
|
+
# link_to @article.title, blog_show_path(id: @article.id)
|
113
130
|
#
|
114
131
|
# == Pretty URLs
|
115
132
|
#
|
116
133
|
# Routes can generate pretty URLs. For example:
|
117
134
|
#
|
118
|
-
#
|
119
|
-
# :
|
120
|
-
# :
|
121
|
-
# :
|
135
|
+
# get '/articles/:year/:month/:day' => 'articles#find_by_id', constraints: {
|
136
|
+
# year: /\d{4}/,
|
137
|
+
# month: /\d{1,2}/,
|
138
|
+
# day: /\d{1,2}/
|
122
139
|
# }
|
123
140
|
#
|
124
141
|
# Using the route above, the URL "http://localhost:3000/articles/2005/11/06"
|
125
142
|
# maps to
|
126
143
|
#
|
127
|
-
# params = {:
|
144
|
+
# params = {year: '2005', month: '11', day: '06'}
|
128
145
|
#
|
129
146
|
# == Regular Expressions and parameters
|
130
147
|
# You can specify a regular expression to define a format for a parameter.
|
131
148
|
#
|
132
149
|
# controller 'geocode' do
|
133
|
-
#
|
134
|
-
# :
|
150
|
+
# get 'geocode/:postalcode' => :show, constraints: {
|
151
|
+
# postalcode: /\d{5}(-\d{4})?/
|
135
152
|
# }
|
153
|
+
# end
|
136
154
|
#
|
137
155
|
# Constraints can include the 'ignorecase' and 'extended syntax' regular
|
138
156
|
# expression modifiers:
|
139
157
|
#
|
140
158
|
# controller 'geocode' do
|
141
|
-
#
|
142
|
-
# :
|
159
|
+
# get 'geocode/:postalcode' => :show, constraints: {
|
160
|
+
# postalcode: /hx\d\d\s\d[a-z]{2}/i
|
143
161
|
# }
|
144
162
|
# end
|
145
163
|
#
|
146
164
|
# controller 'geocode' do
|
147
|
-
#
|
148
|
-
# :
|
165
|
+
# get 'geocode/:postalcode' => :show, constraints: {
|
166
|
+
# postalcode: /# Postalcode format
|
149
167
|
# \d{5} #Prefix
|
150
168
|
# (-\d{4})? #Suffix
|
151
169
|
# /x
|
152
170
|
# }
|
153
171
|
# end
|
154
172
|
#
|
155
|
-
# Using the multiline
|
173
|
+
# Using the multiline modifier will raise an +ArgumentError+.
|
156
174
|
# Encoding regular expression modifiers are silently ignored. The
|
157
175
|
# match will always use the default encoding or ASCII.
|
158
176
|
#
|
159
|
-
# ==
|
160
|
-
#
|
161
|
-
# Consider the following route, which you will find commented out at the
|
162
|
-
# bottom of your generated <tt>config/routes.rb</tt>:
|
163
|
-
#
|
164
|
-
# match ':controller(/:action(/:id))(.:format)'
|
165
|
-
#
|
166
|
-
# This route states that it expects requests to consist of a
|
167
|
-
# <tt>:controller</tt> followed optionally by an <tt>:action</tt> that in
|
168
|
-
# turn is followed optionally by an <tt>:id</tt>, which in turn is followed
|
169
|
-
# optionally by a <tt>:format</tt>.
|
170
|
-
#
|
171
|
-
# Suppose you get an incoming request for <tt>/blog/edit/22</tt>, you'll end
|
172
|
-
# up with:
|
173
|
-
#
|
174
|
-
# params = { :controller => 'blog',
|
175
|
-
# :action => 'edit',
|
176
|
-
# :id => '22'
|
177
|
-
# }
|
178
|
-
#
|
179
|
-
# By not relying on default routes, you improve the security of your
|
180
|
-
# application since not all controller actions, which includes actions you
|
181
|
-
# might add at a later time, are exposed by default.
|
182
|
-
#
|
183
|
-
# == HTTP Methods
|
184
|
-
#
|
185
|
-
# Using the <tt>:via</tt> option when specifying a route allows you to restrict it to a specific HTTP method.
|
186
|
-
# Possible values are <tt>:post</tt>, <tt>:get</tt>, <tt>:put</tt>, <tt>:delete</tt> and <tt>:any</tt>.
|
187
|
-
# If your route needs to respond to more than one method you can use an array, e.g. <tt>[ :get, :post ]</tt>.
|
188
|
-
# The default value is <tt>:any</tt> which means that the route will respond to any of the HTTP methods.
|
189
|
-
#
|
190
|
-
# Examples:
|
191
|
-
#
|
192
|
-
# match 'post/:id' => 'posts#show', :via => :get
|
193
|
-
# match 'post/:id' => "posts#create_comment', :via => :post
|
194
|
-
#
|
195
|
-
# Now, if you POST to <tt>/posts/:id</tt>, it will route to the <tt>create_comment</tt> action. A GET on the same
|
196
|
-
# URL will route to the <tt>show</tt> action.
|
197
|
-
#
|
198
|
-
# === HTTP helper methods
|
199
|
-
#
|
200
|
-
# An alternative method of specifying which HTTP method a route should respond to is to use the helper
|
201
|
-
# methods <tt>get</tt>, <tt>post</tt>, <tt>put</tt> and <tt>delete</tt>.
|
177
|
+
# == External redirects
|
202
178
|
#
|
203
|
-
#
|
179
|
+
# You can redirect any path to another path using the redirect helper in your router:
|
204
180
|
#
|
205
|
-
# get
|
206
|
-
# post 'post/:id' => "posts#create_comment'
|
181
|
+
# get "/stories" => redirect("/posts")
|
207
182
|
#
|
208
|
-
#
|
209
|
-
# however if your route needs to respond to more than one HTTP method (or all methods) then using the
|
210
|
-
# <tt>:via</tt> option on <tt>match</tt> is preferable.
|
183
|
+
# == Unicode character routes
|
211
184
|
#
|
212
|
-
#
|
185
|
+
# You can specify unicode character routes in your router:
|
213
186
|
#
|
214
|
-
#
|
215
|
-
#
|
216
|
-
# match "/stories" => redirect("/posts")
|
187
|
+
# get "こんにちは" => "welcome#index"
|
217
188
|
#
|
218
189
|
# == Routing to Rack Applications
|
219
190
|
#
|
@@ -221,7 +192,7 @@ module ActionDispatch
|
|
221
192
|
# index action in the PostsController, you can specify any Rack application
|
222
193
|
# as the endpoint for a matcher:
|
223
194
|
#
|
224
|
-
#
|
195
|
+
# get "/application.js" => Sprockets
|
225
196
|
#
|
226
197
|
# == Reloading routes
|
227
198
|
#
|
@@ -229,7 +200,7 @@ module ActionDispatch
|
|
229
200
|
#
|
230
201
|
# Rails.application.reload_routes!
|
231
202
|
#
|
232
|
-
# This will clear all named routes and reload routes.rb if the file has been modified from
|
203
|
+
# This will clear all named routes and reload config/routes.rb if the file has been modified from
|
233
204
|
# last load. To absolutely force reloading, use <tt>reload!</tt>.
|
234
205
|
#
|
235
206
|
# == Testing Routes
|
@@ -239,7 +210,7 @@ module ActionDispatch
|
|
239
210
|
# === +assert_routing+
|
240
211
|
#
|
241
212
|
# def test_movie_route_properly_splits
|
242
|
-
# opts = {:
|
213
|
+
# opts = {controller: "plugin", action: "checkout", id: "2"}
|
243
214
|
# assert_routing "plugin/checkout/2", opts
|
244
215
|
# end
|
245
216
|
#
|
@@ -248,7 +219,7 @@ module ActionDispatch
|
|
248
219
|
# === +assert_recognizes+
|
249
220
|
#
|
250
221
|
# def test_route_has_options
|
251
|
-
# opts = {:
|
222
|
+
# opts = {controller: "plugin", action: "show", id: "12"}
|
252
223
|
# assert_recognizes opts, "/plugins/show/12"
|
253
224
|
# end
|
254
225
|
#
|
@@ -261,7 +232,6 @@ module ActionDispatch
|
|
261
232
|
# def send_to_jail
|
262
233
|
# get '/jail'
|
263
234
|
# assert_response :success
|
264
|
-
# assert_template "jail/front"
|
265
235
|
# end
|
266
236
|
#
|
267
237
|
# def goes_to_login
|
@@ -271,23 +241,20 @@ module ActionDispatch
|
|
271
241
|
#
|
272
242
|
# == View a list of all your routes
|
273
243
|
#
|
274
|
-
#
|
244
|
+
# rails routes
|
275
245
|
#
|
276
|
-
# Target specific controllers by prefixing the command with <tt
|
246
|
+
# Target specific controllers by prefixing the command with <tt>-c</tt> option.
|
277
247
|
#
|
278
248
|
module Routing
|
279
|
-
|
280
|
-
autoload :RouteSet, 'action_dispatch/routing/route_set'
|
281
|
-
autoload :RoutesProxy, 'action_dispatch/routing/routes_proxy'
|
282
|
-
autoload :UrlFor, 'action_dispatch/routing/url_for'
|
283
|
-
autoload :PolymorphicRoutes, 'action_dispatch/routing/polymorphic_routes'
|
249
|
+
extend ActiveSupport::Autoload
|
284
250
|
|
285
|
-
|
286
|
-
|
251
|
+
autoload :Mapper
|
252
|
+
autoload :RouteSet
|
253
|
+
autoload :RoutesProxy
|
254
|
+
autoload :UrlFor
|
255
|
+
autoload :PolymorphicRoutes
|
287
256
|
|
288
|
-
|
289
|
-
|
290
|
-
include PolymorphicRoutes
|
291
|
-
end
|
257
|
+
SEPARATORS = %w( / . ? ) #:nodoc:
|
258
|
+
HTTP_METHODS = [:get, :head, :post, :patch, :put, :delete, :options] #:nodoc:
|
292
259
|
end
|
293
260
|
end
|