aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/CHANGELOG2
-rw-r--r--actionpack/lib/action_controller/routing.rb5
-rw-r--r--actionpack/test/controller/routing_test.rb12
3 files changed, 16 insertions, 3 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index 87afe5647b..f7f2066936 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Fixed that named routes didn't use the default values for action and possible other parameters #1534 [Nicholas Seckar]
+
* Fixed JavascriptHelper#visual_effect to use camelize such that :blind_up will work #1639 [pelletierm@eastmedia.net]
* Fixed that a SessionRestoreError was thrown if a model object was placed in the session that wasn't available to all controllers. This means that it's no longer necessary to use the 'model :post' work-around in ApplicationController to have a Post model in your session.
diff --git a/actionpack/lib/action_controller/routing.rb b/actionpack/lib/action_controller/routing.rb
index 940136efd0..d69c862989 100644
--- a/actionpack/lib/action_controller/routing.rb
+++ b/actionpack/lib/action_controller/routing.rb
@@ -256,13 +256,14 @@ module ActionController
class Route #:nodoc:
attr_accessor :components, :known
- attr_reader :path, :options, :keys
+ attr_reader :path, :options, :keys, :defaults
def initialize(path, options = {})
@path, @options = path, options
initialize_components path
defaults, conditions = initialize_hashes options.dup
+ @defaults = defaults.dup
configure_components(defaults, conditions)
initialize_keys
end
@@ -576,7 +577,7 @@ module ActionController
end
def name_route(route, name)
- hash = route.known.symbolize_keys
+ hash = route.defaults.merge(route.known).symbolize_keys
hash[:controller] = "/#{hash[:controller]}"
define_method(hash_access_name(name)) { hash }
diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb
index 3b3cee6ae6..48151ba198 100644
--- a/actionpack/test/controller/routing_test.rb
+++ b/actionpack/test/controller/routing_test.rb
@@ -661,7 +661,17 @@ class RouteSetTests < Test::Unit::TestCase
x = setup_for_named_route
assert_equal({:controller => '/content', :action => 'show_page', :title => 'new stuff'},
x.new.send(:page_url, :title => 'new stuff'))
- end
+ end
+
+ def test_named_route_with_default
+ rs.page 'page/:title', :controller => 'content', :action => 'show_page', :title => 'AboutPage'
+ x = setup_for_named_route
+ assert_equal({:controller => '/content', :action => 'show_page', :title => 'AboutPage'},
+ x.new.send(:page_url))
+ assert_equal({:controller => '/content', :action => 'show_page', :title => 'AboutRails'},
+ x.new.send(:page_url, :title => "AboutRails"))
+
+ end
def setup_for_named_route
x = Class.new