I defined some routes as follows:
resources :dashboard, only: [:destroy] do
collection do
get :timesheets
get :users
put :assign_admin
get :admins
put :remove_admin
match ‘/:year/:month/:day’, to:
‘dashboard#list_timesheets_by_start_date’,
as: ‘timesheets_by_date’,
constraints: { year: /\d{4}/, month: /\d{1, 2}/, day: /\d{1,
2}/ },
via: :get
end
end
Running ‘rake routes’ gives the following output:
timesheets_dashboard_index GET /dashboard/timesheets(.:format)
dashboard#timesheets
users_dashboard_index GET /dashboard/users(.:format)
dashboard#users
assign_admin_dashboard_index PUT
/dashboard/assign_admin(.:format)
dashboard#assign_admin
admins_dashboard_index GET /dashboard/admins(.:format)
dashboard#admins
remove_admin_dashboard_index PUT
/dashboard/remove_admin(.:format)
dashboard#remove_admin
timesheets_by_date_dashboard_index GET
/dashboard/:year/:month/:day(.:format)
dashboard#list_timesheets_by_start_date {:year=>/\d{4}/, :month=>/\d{1,
2}/, :day=>/\d{1, 2}/}
dashboard DELETE /dashboard/:id(.:format)
dashboard#destroy
The first question, - is it possible to make the defined routes more
readable, for example remove the trailing part ‘dashboard_index’ and
keep
just ‘dashboard’ for example ?
The second question, the link to display time sheets by date is defined
as
follows in the view:
The helper ‘date_path’ is defined as follows in ApplicationHelper:
def date_path(date)
“#{date.year}/#{date.month}/#{date.day}”
end
def timesheet_week(timesheet)
“#{timesheet.start_date.to_formatted_s(:rfc822)} -
#{timesheet.end_date.to_formatted_s(:rfc822)}”
end
But when clicking on the link for the week of April, 8th, I’m getting
the
error:
No route matches [GET] “/dashboard/2013/4/8”
Any idea how to fix that?
Thank you.