Simple question on rails routing

How does the :default option differ from just setting the key value
pair at the end of the route?

For example:

map.connect ‘index/test/:foo/:bar’, :controller => ‘index’, :action =>
‘test’, :defaults => { :foo => ‘foo’, :bar => ‘bar’ }

map.connect ‘index/test/:foo/:bar’, :controller => ‘index’, :action =>
‘test’, :foo => ‘foo’, :bar => ‘bar’

What is the point of using defaults? They both seem to work as
intended? Thank you

Note: I looked at the Ruby on Rails Routing guide and I tried the
following example from (Rails Routing from the Outside In — Ruby on Rails Guides)

map.connect ‘photos/:id’, :controller => ‘photos’, :action =>
‘show’, :defaults => { :format => ‘jpg’ }

and I get the following error:

/Library/Ruby/Gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
routing/builder.rb:107:in `assign_route_options’: format: No matching
segment exists; cannot assign default (ArgumentError)

It looks like I need to actually have :format defined as part of the
url. Did something change recently? I am using rails 2.3.2

RubyOnRailsNoob wrote:
[…]

Note: I looked at the Ruby on Rails Routing guide and I tried the
following example from (Rails Routing from the Outside In — Ruby on Rails Guides)

map.connect ‘photos/:id’, :controller => ‘photos’, :action =>
‘show’, :defaults => { :format => ‘jpg’ }

and I get the following error:

/Library/Ruby/Gems/1.8/gems/actionpack-2.3.2/lib/action_controller/
routing/builder.rb:107:in `assign_route_options’: format: No matching
segment exists; cannot assign default (ArgumentError)

It looks like I need to actually have :format defined as part of the
url. Did something change recently? I am using rails 2.3.2

:format became a special routing parameter (like :controller and
:action) in 2.3, but the guides should take that into account…

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]