• Stan Hu's avatar
    Fix merge request redirects going to /commits page · 934eb348
    Stan Hu authored
    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:
    
    1. `controller` -> `projects/merge_requests`
    2. `action` -> `show`
    3. `namespace_id`
    4. `project_id`
    5. `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 https://gitlab.com/gitlab-org/gitlab/issues/31357,
    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.
    934eb348
project.rb 19 KB