3.0.0rc ActionController::RoutingError No route matches

Have been developing on 3.0.0beta4 and just updated to 3.0.0.rc.

When I try to link_to() a User object that previously had worked, I get the following: ActionView::Template::Error (No route matches {:action=>"destroy", :controller=>"games", :id=>#<User ..... >

Yet I have in my routes.rb file has resources :users and my "rake routes" shows:                                GET / users/:id(.:format) {:controller=>"users", :action=>"show"}                                PUT / users/:id(.:format) {:controller=>"users", :action=>"update"}                           user DELETE / users/:id(.:format) {:controller=>"users", :action=>"destroy"}                      edit_user GET /users/:id/ edit(.:format) {:controller=>"users", :action=>"edit"}

Whats odd is I'm not trying to link to :action => 'destroy' at all... just to 'show'.

Also when I generate a test scaffold application it completely works.

In routes.rb file: resources :users do     resources :comments   end

Please show the full link_to method that you’re using. Also, where is games coming from? Please show real routes file too.

Sorry, "games" should be "users".... pasted the same error on a different object I was checking it on (Game).

I've verified its just about any link_to to an object. Here's the exact one: <%= link_to "user.login".html_safe, user %>

Using ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]

Heres the full trace (and I verified it isnt active_scaffold): actionpack (3.0.0.rc) lib/action_dispatch/routing/route_set.rb:398:in `generate' actionpack (3.0.0.rc) lib/action_dispatch/routing/route_set.rb:450:in `generate_without_nil_id_awareness' vendor/plugins/active_scaffold/lib/extensions/nil_id_in_url_params.rb: 4:in `generate' actionpack (3.0.0.rc) lib/action_dispatch/routing/route_set.rb:478:in `url_for' actionpack (3.0.0.rc) lib/action_dispatch/routing/url_for.rb:132:in `url_for' actionpack (3.0.0.rc) lib/action_view/helpers/url_helper.rb:99:in `url_for' actionpack (3.0.0.rc) lib/action_dispatch/routing/route_set.rb:195:in `game_path' actionpack (3.0.0.rc) lib/action_dispatch/routing/ polymorphic_routes.rb:114:in `send' actionpack (3.0.0.rc) lib/action_dispatch/routing/ polymorphic_routes.rb:114:in `polymorphic_url' actionpack (3.0.0.rc) lib/action_dispatch/routing/ polymorphic_routes.rb:120:in `polymorphic_path' actionpack (3.0.0.rc) lib/action_view/helpers/url_helper.rb:103:in `url_for' actionpack (3.0.0.rc) lib/action_view/helpers/url_helper.rb:236:in `link_to' app/views/main/index.html.erb:10:in `_app_views_main_index_html_erb__58309089_2172663760_0' app/views/main/index.html.erb:8:in `each' app/views/main/index.html.erb:8:in `_app_views_main_index_html_erb__58309089_2172663760_0' actionpack (3.0.0.rc) lib/action_view/template.rb:135:in `send' actionpack (3.0.0.rc) lib/action_view/template.rb:135:in `render' activesupport (3.0.0.rc) lib/active_support/notifications.rb:54:in `instrument' actionpack (3.0.0.rc) lib/action_view/template.rb:127:in `render' actionpack (3.0.0.rc) lib/action_view/render/rendering.rb:59:in `_render_template' activesupport (3.0.0.rc) lib/active_support/notifications.rb:52:in `instrument' activesupport (3.0.0.rc) lib/active_support/notifications/ instrumenter.rb:21:in `instrument' activesupport (3.0.0.rc) lib/active_support/notifications.rb:52:in `instrument' actionpack (3.0.0.rc) lib/action_view/render/rendering.rb:56:in `_render_template' actionpack (3.0.0.rc) lib/action_view/render/rendering.rb:26:in `render_without_active_scaffold' vendor/plugins/active_scaffold/lib/extensions/action_view_rendering.rb: 71:in `render' actionpack (3.0.0.rc) lib/abstract_controller/rendering.rb:114:in `_render_template' actionpack (3.0.0.rc) lib/abstract_controller/rendering.rb:108:in `render_to_body' actionpack (3.0.0.rc) lib/action_controller/metal/renderers.rb:47:in `render_to_body' actionpack (3.0.0.rc) lib/action_controller/metal/compatibility.rb: 55:in `render_to_body' actionpack (3.0.0.rc) lib/abstract_controller/rendering.rb:101:in `render_to_string' actionpack (3.0.0.rc) lib/abstract_controller/rendering.rb:92:in `render' actionpack (3.0.0.rc) lib/action_controller/metal/rendering.rb:17:in `render' actionpack (3.0.0.rc) lib/action_controller/metal/instrumentation.rb: 40:in `render_without_active_scaffold' activesupport (3.0.0.rc) lib/active_support/core_ext/benchmark.rb:5:in `ms' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ 1.8/benchmark.rb:308:in `realtime' activesupport (3.0.0.rc) lib/active_support/core_ext/benchmark.rb:5:in `ms' actionpack (3.0.0.rc) lib/action_controller/metal/instrumentation.rb: 40:in `render_without_active_scaffold' actionpack (3.0.0.rc) lib/action_controller/metal/instrumentation.rb: 78:in `cleanup_view_runtime' activerecord (3.0.0.rc) lib/active_record/railties/ controller_runtime.rb:15:in `cleanup_view_runtime' actionpack (3.0.0.rc) lib/action_controller/metal/instrumentation.rb: 39:in `render_without_active_scaffold' vendor/plugins/active_scaffold/lib/extensions/ action_controller_rendering.rb:13:in `render' actionpack (3.0.0.rc) lib/action_controller/metal/implicit_render.rb: 10:in `default_render' actionpack (3.0.0.rc) lib/action_controller/metal/implicit_render.rb: 5:in `send_action' actionpack (3.0.0.rc) lib/abstract_controller/base.rb:136:in `process_action' actionpack (3.0.0.rc) lib/action_controller/metal/rendering.rb:11:in `process_action' actionpack (3.0.0.rc) lib/abstract_controller/callbacks.rb:18:in `process_action' activesupport (3.0.0.rc) lib/active_support/callbacks.rb:449:in `_run__1683250185__process_action__199225275__callbacks' activesupport (3.0.0.rc) lib/active_support/callbacks.rb:404:in `send' activesupport (3.0.0.rc) lib/active_support/callbacks.rb:404:in `_run_process_action_callbacks' activesupport (3.0.0.rc) lib/active_support/callbacks.rb:93:in `send' activesupport (3.0.0.rc) lib/active_support/callbacks.rb:93:in `run_callbacks' actionpack (3.0.0.rc) lib/abstract_controller/callbacks.rb:17:in `process_action' actionpack (3.0.0.rc) lib/action_controller/metal/instrumentation.rb: 30:in `process_action' activesupport (3.0.0.rc) lib/active_support/notifications.rb:52:in `instrument' activesupport (3.0.0.rc) lib/active_support/notifications/ instrumenter.rb:21:in `instrument' activesupport (3.0.0.rc) lib/active_support/notifications.rb:52:in `instrument' actionpack (3.0.0.rc) lib/action_controller/metal/instrumentation.rb: 29:in `process_action' actionpack (3.0.0.rc) lib/action_controller/metal/rescue.rb:17:in `process_action' actionpack (3.0.0.rc) lib/abstract_controller/base.rb:105:in `process' actionpack (3.0.0.rc) lib/abstract_controller/rendering.rb:40:in `process' actionpack (3.0.0.rc) lib/action_controller/metal.rb:133:in `dispatch' actionpack (3.0.0.rc) lib/action_controller/metal/rack_delegation.rb: 14:in `dispatch' actionpack (3.0.0.rc) lib/action_controller/metal.rb:173:in `action' actionpack (3.0.0.rc) lib/action_dispatch/routing/route_set.rb:62:in `call' actionpack (3.0.0.rc) lib/action_dispatch/routing/route_set.rb:62:in `dispatch' actionpack (3.0.0.rc) lib/action_dispatch/routing/route_set.rb:27:in `call' rack-mount (0.6.9) lib/rack/mount/route_set.rb:148:in `call' rack-mount (0.6.9) lib/rack/mount/code_generation.rb:89:in `recognize' rack-mount (0.6.9) lib/rack/mount/code_generation.rb:66:in `optimized_each' rack-mount (0.6.9) lib/rack/mount/code_generation.rb:88:in `recognize' rack-mount (0.6.9) lib/rack/mount/route_set.rb:139:in `call' actionpack (3.0.0.rc) lib/action_dispatch/routing/route_set.rb:489:in `call' actionpack (3.0.0.rc) lib/action_dispatch/middleware/head.rb:14:in `call' rack (1.2.1) lib/rack/methodoverride.rb:24:in `call' actionpack (3.0.0.rc) lib/action_dispatch/middleware/params_parser.rb: 21:in `call' actionpack (3.0.0.rc) lib/action_dispatch/middleware/flash.rb:177:in `call' actionpack (3.0.0.rc) lib/action_dispatch/middleware/session/ abstract_store.rb:149:in `call' actionpack (3.0.0.rc) lib/action_dispatch/middleware/cookies.rb:268:in `call' activerecord (3.0.0.rc) lib/active_record/query_cache.rb:32:in `call' activerecord (3.0.0.rc) lib/active_record/connection_adapters/abstract/ query_cache.rb:28:in `cache' activerecord (3.0.0.rc) lib/active_record/query_cache.rb:12:in `cache' activerecord (3.0.0.rc) lib/active_record/query_cache.rb:31:in `call' actionpack (3.0.0.rc) lib/action_dispatch/middleware/callbacks.rb: 46:in `call' activesupport (3.0.0.rc) lib/active_support/callbacks.rb:410:in `_run_call_callbacks' actionpack (3.0.0.rc) lib/action_dispatch/middleware/callbacks.rb: 44:in `call' rack (1.2.1) lib/rack/sendfile.rb:107:in `call' actionpack (3.0.0.rc) lib/action_dispatch/middleware/remote_ip.rb: 48:in `call' actionpack (3.0.0.rc) lib/action_dispatch/middleware/ show_exceptions.rb:48:in `call' railties (3.0.0.rc) lib/rails/rack/logger.rb:13:in `call' rack (1.2.1) lib/rack/runtime.rb:17:in `call' activesupport (3.0.0.rc) lib/active_support/cache/strategy/ local_cache.rb:72:in `call' rack (1.2.1) lib/rack/lock.rb:11:in `call' rack (1.2.1) lib/rack/lock.rb:11:in `synchronize' rack (1.2.1) lib/rack/lock.rb:11:in `call' actionpack (3.0.0.rc) lib/action_dispatch/middleware/static.rb:30:in `call' railties (3.0.0.rc) lib/rails/application.rb:168:in `call' railties (3.0.0.rc) lib/rails/application.rb:77:in `send' railties (3.0.0.rc) lib/rails/application.rb:77:in `method_missing' railties (3.0.0.rc) lib/rails/rack/log_tailer.rb:15:in `call' rack (1.2.1) lib/rack/content_length.rb:13:in `call' rack (1.2.1) lib/rack/handler/webrick.rb:52:in `service' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ 1.8/webrick/httpserver.rb:104:in `service' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ 1.8/webrick/httpserver.rb:65:in `run' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ 1.8/webrick/server.rb:173:in `start_thread' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ 1.8/webrick/server.rb:162:in `start' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ 1.8/webrick/server.rb:162:in `start_thread' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ 1.8/webrick/server.rb:95:in `start' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ 1.8/webrick/server.rb:92:in `each' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ 1.8/webrick/server.rb:92:in `start' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ 1.8/webrick/server.rb:23:in `start' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ 1.8/webrick/server.rb:82:in `start' rack (1.2.1) lib/rack/handler/webrick.rb:13:in `run' rack (1.2.1) lib/rack/server.rb:213:in `start' railties (3.0.0.rc) lib/rails/commands/server.rb:65:in `start' railties (3.0.0.rc) lib/rails/commands.rb:30 railties (3.0.0.rc) lib/rails/commands.rb:27:in `tap' railties (3.0.0.rc) lib/rails/commands.rb:27 script/rails:6:in `require' script/rails:6

Another error in my post:

<%= link_to "user.login".html_safe, user %>

should be: <%= link_to "#{user.login}".html_safe, user %>

its been a long day...

For better formatted info:

I looked into changes in the relevant action_dispatch lines, could it be this? http://github.com/rails/rails/commit/a1e795f554e07476f1084a0c76cb8b033d1d0b0c

Judging by your SO post you fixed it, but yes I was going to point out that the error occurs when the id parameter isn’t what Rails wants it to be, in your case the / needs to be %2F… but I don’t sound that smart telling you what you already know though :slight_smile:

No problemo, your reply gave me the hope that help was coming, which inspired me to try and answer my own question :slight_smile:

On another note, %2F is definitely not the optimal solution. It works in webkit (safari,chrome), but in Firefox the URL displays as %2F which completely ruins this whole scheme...

Haven't tested on IE either. Is there any way to do this properly in rails 3? I don't need elegance, just so that it works. I do have this in routes:   match "/users/:id/:slug", :to => 'users#show'

Perhaps a better discussion for SO as well..

Haven't tested on IE either. Is there any way to do this properly in rails 3? I don't need elegance, just so that it works. I do have this in routes: match "/users/:id/:slug", :to => 'users#show'

This is the way to do it properly :). / is a separator in routes, and if you want it to be included in the :id parameter you'll need to escape it. You could also possibly do something along the lines of

match "/users/*id", :to=>'users#show'

But your original solution is clearer.

Koz,

It works nicely and alls well except the one problem I mentioned: in Firefox you actually see the "%2F" in the address bar.

I've added this to SO;

You could make it a non-route separator, such as 1-ryan-bigg. The AR finders can take this:

Person.find(params[:id])

It’ll convert it to an integer, resulting in 1, then do a find on that.

Koz,

It works nicely and alls well except the one problem I mentioned: in Firefox you actually see the "%2F" in the address bar.

Right, but this is because your parameter contains a separator character. There's no getting around this, what you're suggesting is the equivalent of a stray comma in a CSV file, you can't have those.

The *id thing will probably work, and probably do what you're expecting out of the box, however it will be extremely greedy and match /users/1/images/3/comments/5/votes to :controller=>"users", :id=>"1/images/3/comments/5/votes" which isn't what you're after.

The same issue bit me when I included usernames in the URL and one username had a period in it, like “mislav.marohnic”. The fact that the exception was a “no route matches” error completely threw me off path and debugging took more than it should.

Should we try to improve the error message to warn us if URL params contained these characters?

ActionController::RoutingError: the :username parameter with the value “mislav.marohnic” contains characters which are considered route separators.

OK, the above message might be sub-optimal, but it goes a long way towards telling a user what’s really going on.

Why not just override the :id regexp:

  resources :users, :id => /[0-9]+\/[-_a-zA-Z0-9]+/

This would match '/users/123/andrew-white/edit' to users#edit

Andrew

Just to correct the misconception about Rails 3. Rack::Mount doesn't force / to be a route separator - it uses statistical analysis to determine the optimal keys for splitting which when you have a low number of routes may lead to it being dropped.

https://rails.lighthouseapp.com/projects/8994/tickets/4874

Andrew