This project is archived and is in readonly mode.
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
-
Paul Barry June 11th, 2010 @ 10:32 PM
- Tag changed from rails3 routes to rails3 routes, patch
Ok, looks like the problem is with the regexp in the normalize_path method in Mapper, it only works for routes like
(/:foo)/whatever
, not(/foo/:bar)/whatever
. I've attached a patch that should fix it. -
Andrew White June 25th, 2010 @ 09:29 AM
- Assigned user set to Andrew White
Paul, can you rebase your patch against the latest HEAD?
-
Andrew White June 26th, 2010 @ 10:50 AM
- State changed from new to open
- Milestone cleared.
- Importance changed from to High
Thanks Paul. I've taken your patch and extended it to also support optional static segments by themselves as well.
-
Repository June 26th, 2010 @ 11:11 AM
- State changed from open to resolved
(from [d4e1a2ef0d35f322803284a980575fc31ff7b4b6]) Support optional static segements as well [#4832 state:resolved]
Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/d4e1a2ef0d35f322803284a980575f...
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>
People watching this ticket
Attachments
Tags
Referenced by
- 4832 Can't create a route with an prefix optional segment that contains both static and dynamic parts (from [d4e1a2ef0d35f322803284a980575fc31ff7b4b6]) Support...