Topic: Rails 3.1.3 custom routing by date

How to make path helpers for this route?

resources :newsmatch 'news/:year/:month/:day' => 'news#show',    :constraints => { :year => /\d{4}/, :month => /\d{2}/, :day => /\d{2}/ },    :as => 'newsdate'

I tried it many ways, but it not works:

link_to news.created_at.strftime('%d.%m.%Y '), newsdate_path(news.created_at.year, news.created_at.month, news.created_at.day)

I get app error for this line by GET http://localhost:3000/news:

link_to news.created_at.strftime('%d.%m.%Y '), newsdate_path(news.created_at.year, news.created_at.month, news.created_at.day)

How to make it right way?

rake routes http://pastie.org/pastes/3057374/text

P.S. http://localhost:3000/news/2011/11/11 works fine.

Last edited by foxweb (2011-12-22 09:55:29)

Re: Rails 3.1.3 custom routing by date

Resolved by fixing RegExp:

  match 'news/:year/:month/:day' => 'news#show',
    :constraints => { :year => /\d{4}/, :month => /\d{1,2}/, :day => /\d{1,2}/ },
    :as => 'newsdate'