This project is archived and is in readonly mode.
:defaults not in path cause "No matching segment exists" error
Reported by Bill Burcham | April 10th, 2009 @ 05:52 PM | in 3.0.2
This ticket is related to #1092 (closed invalid).
The reviewer of #1092 suggested I use :defaults in routes.rb. The pertinent advice is:
You can also define other defaults in a route by supplying a hash for the :defaults option. This even applies to parameters that are not explicitly defined elsewhere in the route. For example:
map.connect 'photos/:id', :controller => 'photos', :action => 'show', :defaults => { :format => 'jpg' }
With this route, an incoming URL of photos/12 would be dispatched to the show action within the Photos controller, and params[:format] will be set to jpg.
If you create a brand new Rails project and add that route and open the console you'll see that it doesn't work at all:
BillBurcham:Rails Bill$ rails foo
BillBurcham:Rails Bill$ cd foo
# Now edit routes.rb to include just the route described in the documentation above
BillBurcham:foo Bill$ ./script/console
Loading development environment (Rails 2.3.2)
/opt/local/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/routing/builder.rb:107:in `assign_route_options':ArgumentError: format: No matching segment exists; cannot assign default
That's just the behavior I described in my December 23 comment to #1092.
So to recap:
The behavior described in the Agile book (see #1092) continues to partially work. It works for route recognition but is still broken in Rails 2.3.2 when it comes to path generation (the inverse of route recognition).
Furthermore, the alternative suggested by the reviewer of #1092 in guides.rubyonrails.org doesn't work either. In fact its behavior is arguably worse than the behavior described in the Agile book because it breaks route recognition (not just path generation).
Comments and changes to this ticket
-
CancelProfileIsBroken August 6th, 2009 @ 01:41 PM
- Tag changed from 2.3.2, bug, routing to 2.3.2, bug, bugmash, routing
-
Elise Huard August 8th, 2009 @ 10:35 AM
reproduced on edge.
when starting the server:
actionpack/lib/action_controller/routing/builder.rb:109:inassign_route_options': format: No matching segment exists; cannot assign default (ArgumentError)<br/> I'm having a look.
-
Elise Huard August 8th, 2009 @ 11:56 AM
defaults produces an error when used with connect or named routes.
defaults doesn't produce an error for resources or resource, where the segments argument of assign_route_options is an array with one element that respond to :key (and that key is 'format')
but the default doesn't seem to be taken into account (or used) at all.I add tests that reproduces the error (and point towards a solution, maybe), but am not about to start messing about with the structures of segments etc quite yet.
-
Jeremy Kemper August 10th, 2009 @ 02:08 AM
- Assigned user set to josh
-
josh August 10th, 2009 @ 02:12 AM
- State changed from new to open
- Milestone changed from 2.x to 2.3.4
-
josh August 19th, 2009 @ 03:59 PM
- State changed from open to incomplete
-
josh August 31st, 2009 @ 06:58 PM
- State changed from incomplete to stale
-
Andrew White June 25th, 2010 @ 03:46 PM
- Milestone cleared.
- State changed from stale to resolved
- Assigned user changed from josh to Andrew White
This appears to be working now:
# routes.rb resources :users, :defaults => { :locale => 'en' } andyw$ rails c >> app.users_path => "/users"
Please update this ticket if it isn't working for you.
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
Referenced by
- 1939 Bad routing recognition with globbing/format/requirements IMHO there's a link with #2478