aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch
diff options
context:
space:
mode:
authorYehuda Katz <wycats@Yehuda-Katz.local>2009-12-20 14:07:19 -0800
committerYehuda Katz <wycats@Yehuda-Katz.local>2009-12-20 14:07:32 -0800
commite48b4c2dd01877ace901e1c186d04605b53b40d0 (patch)
tree34573441a468cd7df3863a6ddf3526051380e763 /actionpack/lib/action_dispatch
parent8b4735fbd9d5f6bd0c5d04688cc5edcd9b00ccf0 (diff)
downloadrails-e48b4c2dd01877ace901e1c186d04605b53b40d0.tar.gz
rails-e48b4c2dd01877ace901e1c186d04605b53b40d0.tar.bz2
rails-e48b4c2dd01877ace901e1c186d04605b53b40d0.zip
:to => redirect() can take a String using 1.9-style interpolation or proc that takes the path parameters as a Hash
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb14
1 files changed, 10 insertions, 4 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index d480af876d..57e992d7dc 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -132,13 +132,19 @@ module ActionDispatch
map_method(:delete, *args, &block)
end
- def redirect(path, options = {})
+ def redirect(*args, &block)
+ options = args.last.is_a?(Hash) ? args.pop : {}
+
+ path = args.shift || block
+ path_proc = path.is_a?(Proc) ? path : proc {|params| path % params }
status = options[:status] || 301
- lambda { |env|
+
+ lambda do |env|
req = Rack::Request.new(env)
- url = req.scheme + '://' + req.host + path
+ params = path_proc.call(env["action_dispatch.request.path_parameters"])
+ url = req.scheme + '://' + req.host + params
[status, {'Location' => url, 'Content-Type' => 'text/html'}, ['Moved Permanently']]
- }
+ end
end
private