From 3dbf7eeb6d815c367fb6e0731d0b1d62859300cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Thu, 9 Jul 2015 17:39:43 +0200 Subject: [PATCH] Fix broken routes to Cost report due to url_for namespaces A spec concerned with that problem is `spec/features/menu_spec.rb`. Within it, the correct solution is noted, but not applied to the menu items. Depending on the current page the link to the cost reports was broken. This seems to be due to a peculiarity of the rails routing where `url_for controller: :foo` would return a link relative to the controller handling the current request path if the controller was routed to via a namespaced route. Example: `url_for controller: 'cost_reports'` will yield different results ... when on `/projects/ponyo/work_packages`: `/projects/ponyo/cost_reports` (correct) when on `/projects/ponyo/work_packages/calendar`: `/work_packages/cost_reports?project_id=ponyo` This is only relevant for project menu entries, not global ones (`project_id` param is nil)*. Meaning that you have to make sure to force the absolute URL in a project menu entry by specificying the controller as e.g. '/cost_reports' instead of just 'cost_reports'. --- lib/open_project/reporting/engine.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/open_project/reporting/engine.rb b/lib/open_project/reporting/engine.rb index 5fd43b719a..071f1777b4 100644 --- a/lib/open_project/reporting/engine.rb +++ b/lib/open_project/reporting/engine.rb @@ -45,7 +45,7 @@ module OpenProject::Reporting end #menu extensions - menu :top_menu, :cost_reports_global, {controller: 'cost_reports', action: 'index', project_id: nil}, + menu :top_menu, :cost_reports_global, {controller: '/cost_reports', action: 'index', project_id: nil}, caption: :cost_reports_title, if: Proc.new { ( User.current.allowed_to?(:view_time_entries, nil, global: true) || @@ -56,7 +56,7 @@ module OpenProject::Reporting } menu :project_menu, :cost_reports, - {controller: 'cost_reports', action: 'index'}, + {controller: '/cost_reports', action: 'index'}, param: :project_id, after: :time_entries, caption: :cost_reports_title,