Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix a bug in url generation for generic routes.

  • Loading branch information...
commit 86defed5ad6c1ec95b2f07a93982a514e2347749 1 parent 25cb213
@josevalim josevalim authored
View
11 actionpack/lib/action_dispatch/routing/mapper.rb
@@ -129,7 +129,10 @@ def default_controller_and_action
{}
end
- defaults[:controller] ||= @options[:controller] || default_controller
+ defaults[:controller] ||= default_controller
+
+ defaults.delete(:controller) if defaults[:controller].blank?
+ defaults.delete(:action) if defaults[:action].blank?
if defaults[:controller].blank? && segment_keys.exclude?("controller")
raise ArgumentError, "missing :controller"
@@ -177,7 +180,11 @@ def to
end
def default_controller
- @scope[:controller].to_s if @scope[:controller]
+ if @options[:controller]
+ @options[:controller].to_s
+ elsif @scope[:controller]
+ @scope[:controller].to_s
+ end
end
end
View
12 actionpack/test/dispatch/routing_test.rb
@@ -197,6 +197,8 @@ def self.matches?(request)
resource :me
match '/' => 'mes#index'
end
+
+ match "whatever/:controller(/:action(/:id))"
end
end
@@ -979,6 +981,16 @@ def test_path_scope
end
end
+ def test_url_generator_for_generic_route
+ with_test_routes do
+ get 'whatever/foo/bar'
+ assert_equal 'foo#bar', @response.body
+
+ assert_equal 'http://www.example.com/whatever/foo/bar/1',
+ url_for(:controller => "foo", :action => "bar", :id => 1)
+ end
+ end
+
private
def with_test_routes
yield
Please sign in to comment.
Something went wrong with that request. Please try again.