# Defaults in routes

**URL:** <https://www.ruby-forum.com/t/defaults-in-routes/118989>\
**Category:** Rails\
**Created:** [November 1, 2007, 11:39pm UTC](https://www.ruby-forum.com/t/defaults-in-routes/118989 "2007-11-01T23:39:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrewkendall](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/b77776/32.png) [@andrewkendall](https://www.ruby-forum.com/u/andrewkendall)\
**Post date:** [November 1, 2007, 11:39pm UTC](https://www.ruby-forum.com/t/defaults-in-routes/118989/1 "2007-11-01T23:39:49Z")

</div>

Hello,

I have a routes question regarding defaults. If I have a route defined  
as follows…

map.connect ‘events/:year/:month’,  
:controller =\> ‘events’,  
:action =\> ‘index’,  
:defaults =\> {  
:year =\> Date.today.year,  
:month =\> Date.today.month  
}

and I generate a route with these options…  
{:controller =\> ‘events’, :action =\> ‘index’, :year =\> Date.today.year,  
:month =\> Date.today.month}

The resulting url is “/events” and doesn’t include the year and month.  
I want the url to include the year and the month ("/events/2007/11"),  
but still use the defaults if they’re not provided for use in my  
controller.

Basically, if I supply the additional parameters, I want them in the  
generated url and if I don’t include the additional parameters, I’d  
still like the defaults to be set for my action.

Is this possible with routes or do I have to check the params in the  
action myself and set the proper defaults if they don’t exist?

Thanks,  
Andrew
