views:

22

answers:

1

Given the following route:

match "/articles/(:year/(:month/(:day)))" => "articles#index", :constraints => { :year => /\d{4}/, :month => /\d{2}/, :day => /\d{2}/ }

And the following set of URLs:

/articles/2010
/articles/2010/09
/articles/2010/09/08

Does ActiveRecord offer any sort of built-in find method that would allow me to find articles by searching through timestamps with an optionally specific date?

A: 

I would do something like this

date = params[:year] + (params[:month] ? '-' + params[:month] : '') + (params[:day] ? '-' + params[:day] : '') + '%'
@articles = Article.all(:conditions => ['date like ?', date])

Although I'm not sure if it will play nice with the timezones...

jordinl