actionpack 7.0.8.7 → 7.2.2.1

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.
Files changed (171) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +90 -537
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +2 -2
  5. data/lib/abstract_controller/asset_paths.rb +2 -0
  6. data/lib/abstract_controller/base.rb +119 -106
  7. data/lib/abstract_controller/caching/fragments.rb +51 -52
  8. data/lib/abstract_controller/caching.rb +2 -0
  9. data/lib/abstract_controller/callbacks.rb +94 -67
  10. data/lib/abstract_controller/collector.rb +6 -6
  11. data/lib/abstract_controller/deprecator.rb +9 -0
  12. data/lib/abstract_controller/error.rb +2 -0
  13. data/lib/abstract_controller/helpers.rb +121 -91
  14. data/lib/abstract_controller/logger.rb +2 -0
  15. data/lib/abstract_controller/railties/routes_helpers.rb +3 -16
  16. data/lib/abstract_controller/rendering.rb +14 -13
  17. data/lib/abstract_controller/translation.rb +12 -30
  18. data/lib/abstract_controller/url_for.rb +9 -5
  19. data/lib/abstract_controller.rb +8 -0
  20. data/lib/action_controller/api/api_rendering.rb +2 -0
  21. data/lib/action_controller/api.rb +78 -73
  22. data/lib/action_controller/base.rb +199 -141
  23. data/lib/action_controller/caching.rb +16 -11
  24. data/lib/action_controller/deprecator.rb +9 -0
  25. data/lib/action_controller/form_builder.rb +21 -16
  26. data/lib/action_controller/log_subscriber.rb +19 -5
  27. data/lib/action_controller/metal/allow_browser.rb +123 -0
  28. data/lib/action_controller/metal/basic_implicit_render.rb +2 -0
  29. data/lib/action_controller/metal/conditional_get.rb +187 -174
  30. data/lib/action_controller/metal/content_security_policy.rb +26 -25
  31. data/lib/action_controller/metal/cookies.rb +4 -2
  32. data/lib/action_controller/metal/data_streaming.rb +65 -54
  33. data/lib/action_controller/metal/default_headers.rb +6 -2
  34. data/lib/action_controller/metal/etag_with_flash.rb +4 -0
  35. data/lib/action_controller/metal/etag_with_template_digest.rb +18 -14
  36. data/lib/action_controller/metal/exceptions.rb +19 -9
  37. data/lib/action_controller/metal/flash.rb +12 -10
  38. data/lib/action_controller/metal/head.rb +20 -16
  39. data/lib/action_controller/metal/helpers.rb +64 -67
  40. data/lib/action_controller/metal/http_authentication.rb +212 -199
  41. data/lib/action_controller/metal/implicit_render.rb +21 -17
  42. data/lib/action_controller/metal/instrumentation.rb +22 -12
  43. data/lib/action_controller/metal/live.rb +125 -92
  44. data/lib/action_controller/metal/logging.rb +6 -4
  45. data/lib/action_controller/metal/mime_responds.rb +151 -142
  46. data/lib/action_controller/metal/parameter_encoding.rb +34 -32
  47. data/lib/action_controller/metal/params_wrapper.rb +58 -58
  48. data/lib/action_controller/metal/permissions_policy.rb +14 -13
  49. data/lib/action_controller/metal/rate_limiting.rb +62 -0
  50. data/lib/action_controller/metal/redirecting.rb +110 -84
  51. data/lib/action_controller/metal/renderers.rb +50 -49
  52. data/lib/action_controller/metal/rendering.rb +103 -82
  53. data/lib/action_controller/metal/request_forgery_protection.rb +279 -161
  54. data/lib/action_controller/metal/rescue.rb +12 -8
  55. data/lib/action_controller/metal/streaming.rb +174 -132
  56. data/lib/action_controller/metal/strong_parameters.rb +598 -473
  57. data/lib/action_controller/metal/testing.rb +2 -0
  58. data/lib/action_controller/metal/url_for.rb +23 -14
  59. data/lib/action_controller/metal.rb +145 -61
  60. data/lib/action_controller/railtie.rb +25 -9
  61. data/lib/action_controller/railties/helpers.rb +2 -0
  62. data/lib/action_controller/renderer.rb +105 -66
  63. data/lib/action_controller/template_assertions.rb +4 -2
  64. data/lib/action_controller/test_case.rb +157 -128
  65. data/lib/action_controller.rb +17 -3
  66. data/lib/action_dispatch/constants.rb +34 -0
  67. data/lib/action_dispatch/deprecator.rb +9 -0
  68. data/lib/action_dispatch/http/cache.rb +28 -29
  69. data/lib/action_dispatch/http/content_disposition.rb +2 -0
  70. data/lib/action_dispatch/http/content_security_policy.rb +48 -45
  71. data/lib/action_dispatch/http/filter_parameters.rb +18 -8
  72. data/lib/action_dispatch/http/filter_redirect.rb +22 -1
  73. data/lib/action_dispatch/http/headers.rb +23 -21
  74. data/lib/action_dispatch/http/mime_negotiation.rb +37 -48
  75. data/lib/action_dispatch/http/mime_type.rb +60 -30
  76. data/lib/action_dispatch/http/mime_types.rb +5 -1
  77. data/lib/action_dispatch/http/parameters.rb +12 -10
  78. data/lib/action_dispatch/http/permissions_policy.rb +32 -27
  79. data/lib/action_dispatch/http/rack_cache.rb +4 -0
  80. data/lib/action_dispatch/http/request.rb +132 -79
  81. data/lib/action_dispatch/http/response.rb +136 -103
  82. data/lib/action_dispatch/http/upload.rb +19 -15
  83. data/lib/action_dispatch/http/url.rb +75 -73
  84. data/lib/action_dispatch/journey/formatter.rb +19 -6
  85. data/lib/action_dispatch/journey/gtg/builder.rb +4 -3
  86. data/lib/action_dispatch/journey/gtg/simulator.rb +2 -0
  87. data/lib/action_dispatch/journey/gtg/transition_table.rb +10 -8
  88. data/lib/action_dispatch/journey/nfa/dot.rb +2 -0
  89. data/lib/action_dispatch/journey/nodes/node.rb +6 -5
  90. data/lib/action_dispatch/journey/parser.rb +4 -3
  91. data/lib/action_dispatch/journey/parser_extras.rb +2 -0
  92. data/lib/action_dispatch/journey/path/pattern.rb +18 -15
  93. data/lib/action_dispatch/journey/route.rb +12 -9
  94. data/lib/action_dispatch/journey/router/utils.rb +16 -15
  95. data/lib/action_dispatch/journey/router.rb +13 -10
  96. data/lib/action_dispatch/journey/routes.rb +6 -4
  97. data/lib/action_dispatch/journey/scanner.rb +4 -2
  98. data/lib/action_dispatch/journey/visitors.rb +2 -0
  99. data/lib/action_dispatch/journey.rb +2 -0
  100. data/lib/action_dispatch/log_subscriber.rb +25 -0
  101. data/lib/action_dispatch/middleware/actionable_exceptions.rb +7 -6
  102. data/lib/action_dispatch/middleware/assume_ssl.rb +27 -0
  103. data/lib/action_dispatch/middleware/callbacks.rb +4 -0
  104. data/lib/action_dispatch/middleware/cookies.rb +192 -194
  105. data/lib/action_dispatch/middleware/debug_exceptions.rb +36 -27
  106. data/lib/action_dispatch/middleware/debug_locks.rb +18 -13
  107. data/lib/action_dispatch/middleware/debug_view.rb +9 -2
  108. data/lib/action_dispatch/middleware/exception_wrapper.rb +181 -27
  109. data/lib/action_dispatch/middleware/executor.rb +9 -1
  110. data/lib/action_dispatch/middleware/flash.rb +65 -46
  111. data/lib/action_dispatch/middleware/host_authorization.rb +22 -17
  112. data/lib/action_dispatch/middleware/public_exceptions.rb +12 -8
  113. data/lib/action_dispatch/middleware/reloader.rb +9 -5
  114. data/lib/action_dispatch/middleware/remote_ip.rb +88 -83
  115. data/lib/action_dispatch/middleware/request_id.rb +15 -8
  116. data/lib/action_dispatch/middleware/server_timing.rb +8 -6
  117. data/lib/action_dispatch/middleware/session/abstract_store.rb +7 -0
  118. data/lib/action_dispatch/middleware/session/cache_store.rb +14 -7
  119. data/lib/action_dispatch/middleware/session/cookie_store.rb +32 -25
  120. data/lib/action_dispatch/middleware/session/mem_cache_store.rb +9 -3
  121. data/lib/action_dispatch/middleware/show_exceptions.rb +42 -28
  122. data/lib/action_dispatch/middleware/ssl.rb +60 -45
  123. data/lib/action_dispatch/middleware/stack.rb +15 -9
  124. data/lib/action_dispatch/middleware/static.rb +40 -34
  125. data/lib/action_dispatch/middleware/templates/rescues/_actions.html.erb +2 -2
  126. data/lib/action_dispatch/middleware/templates/rescues/_message_and_suggestions.html.erb +4 -4
  127. data/lib/action_dispatch/middleware/templates/rescues/_source.html.erb +8 -1
  128. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb +7 -7
  129. data/lib/action_dispatch/middleware/templates/rescues/diagnostics.text.erb +2 -2
  130. data/lib/action_dispatch/middleware/templates/rescues/layout.erb +17 -0
  131. data/lib/action_dispatch/middleware/templates/rescues/missing_exact_template.html.erb +16 -12
  132. data/lib/action_dispatch/middleware/templates/rescues/missing_template.html.erb +1 -1
  133. data/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb +3 -3
  134. data/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb +4 -4
  135. data/lib/action_dispatch/middleware/templates/rescues/unknown_action.html.erb +1 -1
  136. data/lib/action_dispatch/middleware/templates/rescues/unknown_action.text.erb +1 -1
  137. data/lib/action_dispatch/middleware/templates/routes/_route.html.erb +3 -0
  138. data/lib/action_dispatch/middleware/templates/routes/_table.html.erb +47 -38
  139. data/lib/action_dispatch/railtie.rb +12 -4
  140. data/lib/action_dispatch/request/session.rb +39 -27
  141. data/lib/action_dispatch/request/utils.rb +10 -3
  142. data/lib/action_dispatch/routing/endpoint.rb +2 -0
  143. data/lib/action_dispatch/routing/inspector.rb +59 -9
  144. data/lib/action_dispatch/routing/mapper.rb +686 -639
  145. data/lib/action_dispatch/routing/polymorphic_routes.rb +70 -61
  146. data/lib/action_dispatch/routing/redirection.rb +52 -38
  147. data/lib/action_dispatch/routing/route_set.rb +106 -62
  148. data/lib/action_dispatch/routing/routes_proxy.rb +16 -19
  149. data/lib/action_dispatch/routing/url_for.rb +131 -122
  150. data/lib/action_dispatch/routing.rb +152 -150
  151. data/lib/action_dispatch/system_test_case.rb +91 -81
  152. data/lib/action_dispatch/system_testing/browser.rb +27 -19
  153. data/lib/action_dispatch/system_testing/driver.rb +16 -22
  154. data/lib/action_dispatch/system_testing/server.rb +2 -0
  155. data/lib/action_dispatch/system_testing/test_helpers/screenshot_helper.rb +53 -31
  156. data/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb +2 -0
  157. data/lib/action_dispatch/testing/assertion_response.rb +9 -7
  158. data/lib/action_dispatch/testing/assertions/response.rb +36 -26
  159. data/lib/action_dispatch/testing/assertions/routing.rb +203 -95
  160. data/lib/action_dispatch/testing/assertions.rb +5 -1
  161. data/lib/action_dispatch/testing/integration.rb +240 -229
  162. data/lib/action_dispatch/testing/request_encoder.rb +6 -1
  163. data/lib/action_dispatch/testing/test_helpers/page_dump_helper.rb +35 -0
  164. data/lib/action_dispatch/testing/test_process.rb +14 -9
  165. data/lib/action_dispatch/testing/test_request.rb +4 -2
  166. data/lib/action_dispatch/testing/test_response.rb +34 -19
  167. data/lib/action_dispatch.rb +52 -21
  168. data/lib/action_pack/gem_version.rb +6 -4
  169. data/lib/action_pack/version.rb +3 -1
  170. data/lib/action_pack.rb +18 -17
  171. metadata +86 -27
@@ -1,102 +1,111 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # :markup: markdown
4
+
3
5
  module ActionDispatch
4
6
  module Routing
5
- # Polymorphic URL helpers are methods for smart resolution to a named route call when
6
- # given an Active Record model instance. They are to be used in combination with
7
- # ActionController::Resources.
7
+ # # Action Dispatch Routing PolymorphicRoutes
8
+ #
9
+ # Polymorphic URL helpers are methods for smart resolution to a named route call
10
+ # when given an Active Record model instance. They are to be used in combination
11
+ # with ActionController::Resources.
8
12
  #
9
- # These methods are useful when you want to generate the correct URL or path to a RESTful
10
- # resource without having to know the exact type of the record in question.
13
+ # These methods are useful when you want to generate the correct URL or path to
14
+ # a RESTful resource without having to know the exact type of the record in
15
+ # question.
11
16
  #
12
- # Nested resources and/or namespaces are also supported, as illustrated in the example:
17
+ # Nested resources and/or namespaces are also supported, as illustrated in the
18
+ # example:
13
19
  #
14
- # polymorphic_url([:admin, @article, @comment])
20
+ # polymorphic_url([:admin, @article, @comment])
15
21
  #
16
22
  # results in:
17
23
  #
18
- # admin_article_comment_url(@article, @comment)
24
+ # admin_article_comment_url(@article, @comment)
25
+ #
26
+ # ## Usage within the framework
19
27
  #
20
- # == Usage within the framework
28
+ # Polymorphic URL helpers are used in a number of places throughout the Rails
29
+ # framework:
21
30
  #
22
- # Polymorphic URL helpers are used in a number of places throughout the \Rails framework:
31
+ # * `url_for`, so you can use it with a record as the argument, e.g.
32
+ # `url_for(@article)`;
33
+ # * ActionView::Helpers::FormHelper uses `polymorphic_path`, so you can write
34
+ # `form_for(@article)` without having to specify `:url` parameter for the
35
+ # form action;
36
+ # * `redirect_to` (which, in fact, uses `url_for`) so you can write
37
+ # `redirect_to(post)` in your controllers;
38
+ # * ActionView::Helpers::AtomFeedHelper, so you don't have to explicitly
39
+ # specify URLs for feed entries.
23
40
  #
24
- # * <tt>url_for</tt>, so you can use it with a record as the argument, e.g.
25
- # <tt>url_for(@article)</tt>;
26
- # * ActionView::Helpers::FormHelper uses <tt>polymorphic_path</tt>, so you can write
27
- # <tt>form_for(@article)</tt> without having to specify <tt>:url</tt> parameter for the form
28
- # action;
29
- # * <tt>redirect_to</tt> (which, in fact, uses <tt>url_for</tt>) so you can write
30
- # <tt>redirect_to(post)</tt> in your controllers;
31
- # * ActionView::Helpers::AtomFeedHelper, so you don't have to explicitly specify URLs
32
- # for feed entries.
33
41
  #
34
- # == Prefixed polymorphic helpers
42
+ # ## Prefixed polymorphic helpers
35
43
  #
36
- # In addition to <tt>polymorphic_url</tt> and <tt>polymorphic_path</tt> methods, a
37
- # number of prefixed helpers are available as a shorthand to <tt>action: "..."</tt>
38
- # in options. Those are:
44
+ # In addition to `polymorphic_url` and `polymorphic_path` methods, a number of
45
+ # prefixed helpers are available as a shorthand to `action: "..."` in options.
46
+ # Those are:
47
+ #
48
+ # * `edit_polymorphic_url`, `edit_polymorphic_path`
49
+ # * `new_polymorphic_url`, `new_polymorphic_path`
39
50
  #
40
- # * <tt>edit_polymorphic_url</tt>, <tt>edit_polymorphic_path</tt>
41
- # * <tt>new_polymorphic_url</tt>, <tt>new_polymorphic_path</tt>
42
51
  #
43
52
  # Example usage:
44
53
  #
45
- # edit_polymorphic_path(@post) # => "/posts/1/edit"
46
- # polymorphic_path(@post, format: :pdf) # => "/posts/1.pdf"
54
+ # edit_polymorphic_path(@post) # => "/posts/1/edit"
55
+ # polymorphic_path(@post, format: :pdf) # => "/posts/1.pdf"
47
56
  #
48
- # == Usage with mounted engines
57
+ # ## Usage with mounted engines
49
58
  #
50
59
  # If you are using a mounted engine and you need to use a polymorphic_url
51
60
  # pointing at the engine's routes, pass in the engine's route proxy as the first
52
61
  # argument to the method. For example:
53
62
  #
54
- # polymorphic_url([blog, @post]) # calls blog.post_path(@post)
55
- # form_for([blog, @post]) # => "/blog/posts/1"
63
+ # polymorphic_url([blog, @post]) # calls blog.post_path(@post)
64
+ # form_for([blog, @post]) # => "/blog/posts/1"
56
65
  #
57
66
  module PolymorphicRoutes
58
- # Constructs a call to a named RESTful route for the given record and returns the
59
- # resulting URL string. For example:
67
+ # Constructs a call to a named RESTful route for the given record and returns
68
+ # the resulting URL string. For example:
69
+ #
70
+ # # calls post_url(post)
71
+ # polymorphic_url(post) # => "http://example.com/posts/1"
72
+ # polymorphic_url([blog, post]) # => "http://example.com/blogs/1/posts/1"
73
+ # polymorphic_url([:admin, blog, post]) # => "http://example.com/admin/blogs/1/posts/1"
74
+ # polymorphic_url([user, :blog, post]) # => "http://example.com/users/1/blog/posts/1"
75
+ # polymorphic_url(Comment) # => "http://example.com/comments"
60
76
  #
61
- # # calls post_url(post)
62
- # polymorphic_url(post) # => "http://example.com/posts/1"
63
- # polymorphic_url([blog, post]) # => "http://example.com/blogs/1/posts/1"
64
- # polymorphic_url([:admin, blog, post]) # => "http://example.com/admin/blogs/1/posts/1"
65
- # polymorphic_url([user, :blog, post]) # => "http://example.com/users/1/blog/posts/1"
66
- # polymorphic_url(Comment) # => "http://example.com/comments"
77
+ # #### Options
67
78
  #
68
- # ==== Options
79
+ # * `:action` - Specifies the action prefix for the named route: `:new` or
80
+ # `:edit`. Default is no prefix.
81
+ # * `:routing_type` - Allowed values are `:path` or `:url`. Default is `:url`.
69
82
  #
70
- # * <tt>:action</tt> - Specifies the action prefix for the named route:
71
- # <tt>:new</tt> or <tt>:edit</tt>. Default is no prefix.
72
- # * <tt>:routing_type</tt> - Allowed values are <tt>:path</tt> or <tt>:url</tt>.
73
- # Default is <tt>:url</tt>.
74
83
  #
75
- # Also includes all the options from <tt>url_for</tt>. These include such
76
- # things as <tt>:anchor</tt> or <tt>:trailing_slash</tt>. Example usage
77
- # is given below:
84
+ # Also includes all the options from `url_for`. These include such things as
85
+ # `:anchor` or `:trailing_slash`. Example usage is given below:
78
86
  #
79
- # polymorphic_url([blog, post], anchor: 'my_anchor')
80
- # # => "http://example.com/blogs/1/posts/1#my_anchor"
81
- # polymorphic_url([blog, post], anchor: 'my_anchor', script_name: "/my_app")
82
- # # => "http://example.com/my_app/blogs/1/posts/1#my_anchor"
87
+ # polymorphic_url([blog, post], anchor: 'my_anchor')
88
+ # # => "http://example.com/blogs/1/posts/1#my_anchor"
89
+ # polymorphic_url([blog, post], anchor: 'my_anchor', script_name: "/my_app")
90
+ # # => "http://example.com/my_app/blogs/1/posts/1#my_anchor"
83
91
  #
84
- # For all of these options, see the documentation for {url_for}[rdoc-ref:ActionDispatch::Routing::UrlFor].
92
+ # For all of these options, see the documentation for
93
+ # [url_for](rdoc-ref:ActionDispatch::Routing::UrlFor).
85
94
  #
86
- # ==== Functionality
95
+ # #### Functionality
87
96
  #
88
- # # an Article record
89
- # polymorphic_url(record) # same as article_url(record)
97
+ # # an Article record
98
+ # polymorphic_url(record) # same as article_url(record)
90
99
  #
91
- # # a Comment record
92
- # polymorphic_url(record) # same as comment_url(record)
100
+ # # a Comment record
101
+ # polymorphic_url(record) # same as comment_url(record)
93
102
  #
94
- # # it recognizes new records and maps to the collection
95
- # record = Comment.new
96
- # polymorphic_url(record) # same as comments_url()
103
+ # # it recognizes new records and maps to the collection
104
+ # record = Comment.new
105
+ # polymorphic_url(record) # same as comments_url()
97
106
  #
98
- # # the class of a record will also map to the collection
99
- # polymorphic_url(Comment) # same as comments_url()
107
+ # # the class of a record will also map to the collection
108
+ # polymorphic_url(Comment) # same as comments_url()
100
109
  #
101
110
  def polymorphic_url(record_or_hash_or_array, options = {})
102
111
  if Hash === record_or_hash_or_array
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # :markup: markdown
4
+
3
5
  require "active_support/core_ext/array/extract_options"
4
6
  require "rack/utils"
5
7
  require "action_controller/metal/exceptions"
@@ -18,10 +20,19 @@ module ActionDispatch
18
20
  def redirect?; true; end
19
21
 
20
22
  def call(env)
21
- serve Request.new env
23
+ ActiveSupport::Notifications.instrument("redirect.action_dispatch") do |payload|
24
+ request = Request.new(env)
25
+ response = build_response(request)
26
+
27
+ payload[:status] = @status
28
+ payload[:location] = response.headers["Location"]
29
+ payload[:request] = request
30
+
31
+ response.to_a
32
+ end
22
33
  end
23
34
 
24
- def serve(req)
35
+ def build_response(req)
25
36
  uri = URI.parse(path(req.path_parameters, req))
26
37
 
27
38
  unless uri.host
@@ -38,15 +49,15 @@ module ActionDispatch
38
49
 
39
50
  req.commit_flash
40
51
 
41
- body = %(<html><body>You are being <a href="#{ERB::Util.unwrapped_html_escape(uri.to_s)}">redirected</a>.</body></html>)
52
+ body = ""
42
53
 
43
54
  headers = {
44
55
  "Location" => uri.to_s,
45
- "Content-Type" => "text/html",
56
+ "Content-Type" => "text/html; charset=#{ActionDispatch::Response.default_charset}",
46
57
  "Content-Length" => body.length.to_s
47
58
  }
48
59
 
49
- [ status, headers, [body] ]
60
+ ActionDispatch::Response.new(status, headers, body)
50
61
  end
51
62
 
52
63
  def path(params, request)
@@ -59,7 +70,7 @@ module ActionDispatch
59
70
 
60
71
  private
61
72
  def relative_path?(path)
62
- path && !path.empty? && path[0] != "/"
73
+ path && !path.empty? && !path.start_with?("/")
63
74
  end
64
75
 
65
76
  def escape(params)
@@ -137,55 +148,58 @@ module ActionDispatch
137
148
  module Redirection
138
149
  # Redirect any path to another path:
139
150
  #
140
- # get "/stories" => redirect("/posts")
151
+ # get "/stories" => redirect("/posts")
141
152
  #
142
- # This will redirect the user, while ignoring certain parts of the request, including query string, etc.
143
- # <tt>/stories</tt>, <tt>/stories?foo=bar</tt>, etc all redirect to <tt>/posts</tt>.
153
+ # This will redirect the user, while ignoring certain parts of the request,
154
+ # including query string, etc. `/stories`, `/stories?foo=bar`, etc all redirect
155
+ # to `/posts`.
144
156
  #
145
- # The redirect will use a <tt>301 Moved Permanently</tt> status code by
146
- # default. This can be overridden with the +:status+ option:
157
+ # The redirect will use a `301 Moved Permanently` status code by default. This
158
+ # can be overridden with the `:status` option:
147
159
  #
148
- # get "/stories" => redirect("/posts", status: 307)
160
+ # get "/stories" => redirect("/posts", status: 307)
149
161
  #
150
162
  # You can also use interpolation in the supplied redirect argument:
151
163
  #
152
- # get 'docs/:article', to: redirect('/wiki/%{article}')
164
+ # get 'docs/:article', to: redirect('/wiki/%{article}')
153
165
  #
154
- # Note that if you return a path without a leading slash then the URL is prefixed with the
155
- # current SCRIPT_NAME environment variable. This is typically '/' but may be different in
156
- # a mounted engine or where the application is deployed to a subdirectory of a website.
166
+ # Note that if you return a path without a leading slash then the URL is
167
+ # prefixed with the current SCRIPT_NAME environment variable. This is typically
168
+ # '/' but may be different in a mounted engine or where the application is
169
+ # deployed to a subdirectory of a website.
157
170
  #
158
171
  # Alternatively you can use one of the other syntaxes:
159
172
  #
160
- # The block version of redirect allows for the easy encapsulation of any logic associated with
161
- # the redirect in question. Either the params and request are supplied as arguments, or just
162
- # params, depending of how many arguments your block accepts. A string is required as a
163
- # return value.
173
+ # The block version of redirect allows for the easy encapsulation of any logic
174
+ # associated with the redirect in question. Either the params and request are
175
+ # supplied as arguments, or just params, depending of how many arguments your
176
+ # block accepts. A string is required as a return value.
164
177
  #
165
- # get 'jokes/:number', to: redirect { |params, request|
166
- # path = (params[:number].to_i.even? ? "wheres-the-beef" : "i-love-lamp")
167
- # "http://#{request.host_with_port}/#{path}"
168
- # }
178
+ # get 'jokes/:number', to: redirect { |params, request|
179
+ # path = (params[:number].to_i.even? ? "wheres-the-beef" : "i-love-lamp")
180
+ # "http://#{request.host_with_port}/#{path}"
181
+ # }
169
182
  #
170
- # Note that the <tt>do end</tt> syntax for the redirect block wouldn't work, as Ruby would pass
171
- # the block to +get+ instead of +redirect+. Use <tt>{ ... }</tt> instead.
183
+ # Note that the `do end` syntax for the redirect block wouldn't work, as Ruby
184
+ # would pass the block to `get` instead of `redirect`. Use `{ ... }` instead.
172
185
  #
173
- # The options version of redirect allows you to supply only the parts of the URL which need
174
- # to change, it also supports interpolation of the path similar to the first example.
186
+ # The options version of redirect allows you to supply only the parts of the URL
187
+ # which need to change, it also supports interpolation of the path similar to
188
+ # the first example.
175
189
  #
176
- # get 'stores/:name', to: redirect(subdomain: 'stores', path: '/%{name}')
177
- # get 'stores/:name(*all)', to: redirect(subdomain: 'stores', path: '/%{name}%{all}')
178
- # get '/stories', to: redirect(path: '/posts')
190
+ # get 'stores/:name', to: redirect(subdomain: 'stores', path: '/%{name}')
191
+ # get 'stores/:name(*all)', to: redirect(subdomain: 'stores', path: '/%{name}%{all}')
192
+ # get '/stories', to: redirect(path: '/posts')
179
193
  #
180
- # This will redirect the user, while changing only the specified parts of the request,
181
- # for example the +path+ option in the last example.
182
- # <tt>/stories</tt>, <tt>/stories?foo=bar</tt>, redirect to <tt>/posts</tt> and <tt>/posts?foo=bar</tt> respectively.
194
+ # This will redirect the user, while changing only the specified parts of the
195
+ # request, for example the `path` option in the last example. `/stories`,
196
+ # `/stories?foo=bar`, redirect to `/posts` and `/posts?foo=bar` respectively.
183
197
  #
184
- # Finally, an object which responds to call can be supplied to redirect, allowing you to reuse
185
- # common redirect routes. The call method must accept two arguments, params and request, and return
186
- # a string.
198
+ # Finally, an object which responds to call can be supplied to redirect,
199
+ # allowing you to reuse common redirect routes. The call method must accept two
200
+ # arguments, params and request, and return a string.
187
201
  #
188
- # get 'accounts/:name' => redirect(SubdomainRedirector.new('api'))
202
+ # get 'accounts/:name' => redirect(SubdomainRedirector.new('api'))
189
203
  #
190
204
  def redirect(*args, &block)
191
205
  options = args.extract_options!