aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch
diff options
context:
space:
mode:
authorAndrew White <andyw@pixeltrix.co.uk>2012-05-19 11:22:00 +0100
committerAndrew White <andyw@pixeltrix.co.uk>2012-05-19 11:22:00 +0100
commitec774983514d4ce1b593585ae14a17b730ee2c46 (patch)
tree907dfb1fec28621ec9519c164a5bb4057a1ceb7a /actionpack/lib/action_dispatch
parent98657ad10c0bd799b8b314b9af3f0495267b2ddb (diff)
downloadrails-ec774983514d4ce1b593585ae14a17b730ee2c46.tar.gz
rails-ec774983514d4ce1b593585ae14a17b730ee2c46.tar.bz2
rails-ec774983514d4ce1b593585ae14a17b730ee2c46.zip
Improve `rake routes` output for redirects - closes #6369.
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r--actionpack/lib/action_dispatch/routing/redirection.rb34
1 files changed, 22 insertions, 12 deletions
diff --git a/actionpack/lib/action_dispatch/routing/redirection.rb b/actionpack/lib/action_dispatch/routing/redirection.rb
index 3e2a9e232d..b3823bb496 100644
--- a/actionpack/lib/action_dispatch/routing/redirection.rb
+++ b/actionpack/lib/action_dispatch/routing/redirection.rb
@@ -37,10 +37,25 @@ module ActionDispatch
end
def inspect
- "Redirect (#{status})"
+ "redirect(#{status})"
end
end
+ class PathRedirect < Redirect
+ def path(params, request)
+ (params.empty? || !block.match(/%\{\w*\}/)) ? block : (block % escape(params))
+ end
+
+ def inspect
+ "redirect(#{status}, #{block})"
+ end
+
+ private
+ def escape(params)
+ Hash[params.map{ |k,v| [k, Rack::Utils.escape(v)] }]
+ end
+ end
+
class OptionRedirect < Redirect # :nodoc:
alias :options :block
@@ -60,6 +75,10 @@ module ActionDispatch
ActionDispatch::Http::URL.url_for url_options
end
+ def inspect
+ "redirect(#{status}, #{options.map{ |k,v| "#{k}: #{v}" }.join(', ')})"
+ end
+
private
def escape_path(params)
Hash[params.map{ |k,v| [k, URI.parser.escape(v)] }]
@@ -106,24 +125,15 @@ module ActionDispatch
def redirect(*args, &block)
options = args.extract_options!
status = options.delete(:status) || 301
+ path = args.shift
return OptionRedirect.new(status, options) if options.any?
-
- path = args.shift
-
- block = lambda { |params, request|
- (params.empty? || !path.match(/%\{\w*\}/)) ? path : (path % escape(params))
- } if String === path
+ return PathRedirect.new(status, path) if String === path
block = path if path.respond_to? :call
raise ArgumentError, "redirection argument not supported" unless block
Redirect.new status, block
end
-
- private
- def escape(params)
- Hash[params.map{ |k,v| [k, Rack::Utils.escape(v)] }]
- end
end
end
end