views:

1161

answers:

4

Had a working app with Rails 3.0.0beta4 and just updated to the RC. Getting a new strange error. For some reason when I try to:

  <%= link_to "test", user %>

The user is routed as resources :users yet it complains about no route for "action => destroy" despite I'm not even trying to link to destroy:

  ActionController::RoutingError in Main#index
  No route matches {:action=>"destroy", :controller=>"users", :id=>#<User...>}

For reference I'm using ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]

The route is simply:

    resources :users

Running rake routes returns the proper stuff:

                           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"}

I generated a testrails app with scaffolding for users and it works just fine, so must be something in the full trace here. I'm stumped...

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'
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_2173261620_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_2173261620_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'
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'
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'
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'
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:439: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

Could it be from these commits? http://github.com/rails/rails/commit/a1e795f554e07476f1084a0c76cb8b033d1d0b0c

Help is much appreciated!

+1  A: 

Ok heres the deal. I investigated the corresponding code and it was caused by two things. The problem was actually because I had my to_param set as follows:

def to_param
  id + '/' + title.parameterize
end

I needed to keep compatability with old URLs from the non-rails app, thus the '/' rather than the usual -.

The fix is to replace '/' with '%2F'

Relevant commit: http://github.com/rails/rails/commit/622092d33e8d326217ab1ed6138e2c572c95b8ba

proph3t
A: 

The problem you're having is that '/' is a separator in routes, so in order to match you'll need your route to look like

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

Either that, or escape the '/' to '%2F' as you said

NZKoz
Actually I have that in my routes as well, but the '%2F' was still required to fix it. It worked before in beta4 but in RC they changed URL parsing I believe in url_for or routing.
proph3t
A: 

I'm trying to do a user login match like facebook's id

e.g. domain.com/john.doe -> users#show_by_login

How could I hack the routes to make it work? I'm getting the same error you have

No route matches for {:login => "john.doe", :action => "show_by_login", :controller => "users"}

routes.rb I have

match "/:login" => "users#show_by_login", :as => "show_user"

Rex Chung
A: 

I tried this and worked for me in Rails3:

match "/:login" => => "users#show_by_login", :as => "show_user", :constraints => {:login => /.*/) 
Rex Chung