aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--actionpack/lib/action_controller/routing.rb13
-rw-r--r--actionpack/test/controller/routing_test.rb27
3 files changed, 39 insertions, 3 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index 69c968af6e..7b6858ebb1 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Fixed routes so that routes which do not specify :action in the path or in the requirements have a default of :action => 'index', In addition, fixed url generation so that :action => 'index' does not need to be provided for such urls. [Nicholas Seckar, Markjuh]
+
* Worked around a Safari bug where it wouldn't pass headers through if the response was zero length by having render :nothing return ' ' instead of ''
* Fixed Request#subdomains to handle "foo.foo.com" correctly
diff --git a/actionpack/lib/action_controller/routing.rb b/actionpack/lib/action_controller/routing.rb
index f7d3fe3369..fd9904a20e 100644
--- a/actionpack/lib/action_controller/routing.rb
+++ b/actionpack/lib/action_controller/routing.rb
@@ -288,9 +288,16 @@ module ActionController
generator.before, generator.current, generator.after = [], components.first, (components[1..-1] || [])
if known.empty? then generator.go
- else generator.if(generator.check_conditions(known)) {|gp| gp.go }
+ else
+ # Alter the conditions to allow :action => 'index' to also catch :action => nil
+ altered_known = known.collect do |k, v|
+ if k == :action && v== 'index' then [k, [nil, 'index']]
+ else [k, v]
+ end
+ end
+ generator.if(generator.check_conditions(altered_known)) {|gp| gp.go }
end
-
+
generator
end
@@ -363,7 +370,7 @@ module ActionController
def add_default_requirements
component_keys = components.collect {|c| c.key}
- known[:action] ||= [nil, 'index'] unless component_keys.include? :action
+ known[:action] ||= 'index' unless component_keys.include? :action
end
end
diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb
index 1d7613b2ac..c0bc92f6db 100644
--- a/actionpack/test/controller/routing_test.rb
+++ b/actionpack/test/controller/routing_test.rb
@@ -836,6 +836,33 @@ class RouteSetTests < Test::Unit::TestCase
assert_equal ['/', {}], rs.generate(:controller => 'content', :action => 'index')
assert_equal ['/', {}], rs.generate(:controller => 'content')
end
+
+ def test_named_url_with_no_action_specified
+ rs.draw do
+ rs.root '', :controller => 'content'
+ rs.connect ':controller/:action/:id'
+ end
+
+ assert_equal ['/', {}], rs.generate(:controller => 'content', :action => 'index')
+ assert_equal ['/', {}], rs.generate(:controller => 'content')
+
+ x = setup_for_named_route
+ assert_equal({:controller => '/content', :action => 'index'},
+ x.new.send(:root_url))
+ end
+
+ def test_url_generated_when_forgetting_action
+ [{:controller => 'content', :action => 'index'}, {:controller => 'content'}].each do |hash|
+ rs.draw do
+ rs.root '', hash
+ rs.connect ':controller/:action/:id'
+ end
+ assert_equal ['/', {}], rs.generate({:action => nil}, {:controller => 'content', :action => 'hello'})
+ assert_equal ['/', {}], rs.generate({:controller => 'content'})
+ assert_equal ['/content/hi', {}], rs.generate({:controller => 'content', :action => 'hi'})
+ end
+ end
+
end
end