This project is archived and is in readonly mode.

#4832 ✓resolved
Paul Barry

Can't create a route with an prefix optional segment that contains both static and dynamic parts

Reported by Paul Barry | June 11th, 2010 @ 07:24 PM | in 3.0.2

I'm trying to define a route that has an optional prefix segment with a static segment, like this:

get '(/groups/:group_id)/discussions' => "discussions#index"

I would expect GET /discussions to match this with :group_id set to nil and GET /groups/1/discussions to match this with :group_id set to 1. Instead, neither of those routes match. If I define the route like this:

get '/discussions(/groups/:group_id)' => "discussions#index"

GET /discussions matches and GET /discussions/groups/1 matches setting :group_id to 1. Also this:

get '(/:group_id)/discussions' => "discussions#index"

Works, GET /discussions matches and GET /1/discussions matches setting :group_id to 1.

This seems like a bug to me, or is there a reason why this wouldn't work.

I've tested this on REE 1.8.7 on edge 85cc1fa657f441417f36998a32a6a158c2697aad

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Referenced by

Pages