Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[padrino-core] current_path impl

  • Loading branch information...
commit 221ae9f53fd3e9603c9acf2d22f18b08b3d00ba6 1 parent c0b2362
Josh Hull authored
View
10 padrino-core/lib/padrino-core/application/routing.rb
@@ -440,6 +440,7 @@ def route(verb, path, *args, &block)
# Now we can eval route, but because we have "throw halt" we need to be
# (en)sure to reset old layout and run controller after filters.
begin
+ @route = route
@_response_buffer = catch(:halt) { route_eval(&block) }
processed = true
ensure
@@ -662,6 +663,15 @@ def recognize_path(path)
self.class.recognize_path(path)
end
+ def current_path(*path_params)
+ if path_params.last.is_a?(Hash)
+ path_params[-1] = params.merge(path_params[-1])
+ else
+ path_params << params
+ end
+ @route.url(*path_params)
+ end
+
##
# This is mostly just a helper so request.path_info isn't changed when
# serving files from the public directory
View
4 padrino-core/test/test_routing.rb
@@ -1408,7 +1408,7 @@ def authorize(username, password)
assert_equal [:with_format, { :id => "9", :format => "js" }], @app.recognize_path(@app.url(:with_format, :id => 9, :format => :js))
end
- should_eventually 'have current_path' do
+ should 'have current_path' do
mock_app do
controller :foo do
get :bar, :map => "/paginate/:page" do
@@ -1420,7 +1420,7 @@ def authorize(username, password)
assert_equal "/paginate/10", body
end
- should_eventually 'change params in current_path' do
+ should 'change params in current_path' do
mock_app do
get :index, :map => "/paginate/:page" do
current_path(:page => 66)
Please sign in to comment.
Something went wrong with that request. Please try again.