# Simple question on rails routing

**URL:** <https://www.ruby-forum.com/t/simple-question-on-rails-routing/177997>\
**Category:** Rails\
**Created:** [October 27, 2009, 7:15pm UTC](https://www.ruby-forum.com/t/simple-question-on-rails-routing/177997 "2009-10-27T19:15:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![RubyOnRailsNoob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8797f3/32.png) [@RubyOnRailsNoob](https://www.ruby-forum.com/u/RubyOnRailsNoob)\
**Post date:** [October 27, 2009, 7:15pm UTC](https://www.ruby-forum.com/t/simple-question-on-rails-routing/177997/1 "2009-10-27T19:15:22Z")

</div>

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](http://guides.rubyonrails.org/routing.html))

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

---

<div class="post-metadata">

**Author:** ![RubyOnRailsNoob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8797f3/32.png) [@RubyOnRailsNoob](https://www.ruby-forum.com/u/RubyOnRailsNoob)\
**Post date:** [October 27, 2009, 7:49pm UTC](https://www.ruby-forum.com/t/simple-question-on-rails-routing/177997/2 "2009-10-27T19:49:26Z")

</div>

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](http://guides.rubyonrails.org/routing.html))
> 
> 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](http://www.marnen.org)  
removed\_email\_address@domain.invalid
