Fix merge request redirects going to /commits page
When a merge request is redirected to a new project, Rails attempts to
construct the proper URL in url_for
by finding the first route that
matches the given parameters:
-
controller
->projects/merge_requests
-
action
->show
namespace_id
project_id
id
In this example, /*namespace_id/:project_id/commits/*id
matched
instead of /*namespace_id/:project_id/merge_requests/:id
.
This happens because the Rails resources
block defines all the
standard #index
, #show
, #update
, etc. routes after the block runs.
We fixed this issue by explicitly specifying the merge request #show
as the first route.
This is similar to #31357 (closed),
except the solution is a bit simpler because the backend appears to set
a tab
query string, which allows the redirected route to end up in the
right place. For example, visiting the old /merge_requests/:id/commits
appears to cause a redirection to /merge_requests/:id/?tab=commits
,
which does the right thing.