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: <tr> <td><%= link_to timesheet_week(timesheet), "/dashboard/#{date_path(timesheet.start_date)}" %></td> <td><%= timesheet.total_days %> </tr> 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. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/kj7yvoRlMQYJ. For more options, visit https://groups.google.com/groups/opt_out.
The first pont is fixed now: to use a singular route for DashboardController and remove the trailing ''..dashboard_index'', I changed the routes as follows: resource :dashboard, :controller => "dashboard", only: [:destroy] do collection do get :timesheets get :users put :assign_admin get :admins put :remove_admin match ''timesheets/: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 I still have the problem with matching the route to /dashboard/timesheets/:year/:month/:day. Regards On Tuesday, April 9, 2013 12:06:00 PM UTC+2, Serguei Cambour wrote:> > 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: > > <tr> > <td><%= link_to timesheet_week(timesheet), > "/dashboard/#{date_path(timesheet.start_date)}" %></td> > <td><%= timesheet.total_days %> > </tr> > > 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. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/a00hVHI-xPoJ. For more options, visit https://groups.google.com/groups/opt_out.
The second point is also fixed, - the routes should be defined as follows: match ''/timesheets/:date'', to: ''dashboard#list_timesheets_by_start_date'', via: :get, constraints: { date: /\d{4}-\d{,2}-\d{,2}/ }, as: ''timesheets_by_date'' An in the controller, one should just get the date from params: def list_timesheets_by_start_date unless params[:date] @date = Date.today.beginning_of_week end @date ||= Date.strptime(params[:date], ''%Y-%m-%d'') timesheets = Timesheet.find_all_by_start_date(@date) @timesheets = timesheets.paginate(page: params[:page]) render ''selection'' end Hope this helps. Regards On Tuesday, April 9, 2013 12:06:00 PM UTC+2, Serguei Cambour wrote:> > 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: > > <tr> > <td><%= link_to timesheet_week(timesheet), > "/dashboard/#{date_path(timesheet.start_date)}" %></td> > <td><%= timesheet.total_days %> > </tr> > > 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. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/LPl7-0GvWBgJ. For more options, visit https://groups.google.com/groups/opt_out.