Rails 3.1.3 custom date routing

How to make track assistants for this route?

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

I tried many ways, but it does not work:

 link_to news.created_at.strftime '%d.%m.%Y ', newsdate_path(:year => '2011', :month => '11', :day => '11') 

I get an application error for this line using GET http: // localhost: 3000 / news :

 ArgumentError in News#index Showing /home/foxweb/work/dev/app/views/news/index.html.slim where line #6 raised: wrong number of arguments (2 for 1) 

How to make the right way?

PS http: // localhost: 3000 / news / 2011/11/11 works fine.

+4
source share
1 answer

Oh, this common mistake. You need to take strftime arguments in braces.

 link_to news.created_at.strftime('%d.%m.%Y'), newsdate_path(:year => '2011', :month => '11', :day => '11') 

What all!

+5
source

Source: https://habr.com/ru/post/1387475/


All Articles