Skip to content

Instantly share code, notes, and snippets.

@repertoire
Created July 1, 2011 12:11
Show Gist options
  • Save repertoire/1058421 to your computer and use it in GitHub Desktop.
Save repertoire/1058421 to your computer and use it in GitHub Desktop.
WTF is going on with named resource routes
$ be rake routes | grep document
/opt/local/lib/ruby1.9/gems/1.9.1/gems/rake-0.9.2/lib/rake/file_utils.rb:10: warning: already initialized constant RUBY
/opt/local/lib/ruby1.9/gems/1.9.1/gems/rake-0.9.2/lib/rake/file_utils.rb:84: warning: already initialized constant LN_SUPPORTED
documents GET /documents(.:format) {:action=>"index", :controller=>"documents"}
POST /documents(.:format) {:action=>"create", :controller=>"documents"}
new_document GET /documents/new(.:format) {:action=>"new", :controller=>"documents"}
edit_document GET /documents/:id/edit(.:format) {:action=>"edit", :controller=>"documents"}
document GET /documents/:id(.:format) {:action=>"show", :controller=>"documents"}
PUT /documents/:id(.:format) {:action=>"update", :controller=>"documents"}
DELETE /documents/:id(.:format) {:action=>"destroy", :controller=>"documents"}
$
MyApp::Application.routes.draw do
resources :documents
end
irb(main):001:0> @documents = Document.all
irb(main):002:0> @documents.count
=> 435
irb(main):003:0> helper.url_for(@documents.last)
NoMethodError: undefined method `document_path' for #<ActionView::Base:0x0000010f44cf40>
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/actionpack-3.0.9/lib/action_dispatch/routing/polymorphic_routes.rb:114:in `polymorphic_url'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/actionpack-3.0.9/lib/action_dispatch/routing/polymorphic_routes.rb:120:in `polymorphic_path'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/actionpack-3.0.9/lib/action_view/helpers/url_helper.rb:103:in `url_for'
from (irb):3
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/railties-3.0.9/lib/rails/commands/console.rb:44:in `start'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/railties-3.0.9/lib/rails/commands/console.rb:8:in `start'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/railties-3.0.9/lib/rails/commands.rb:23:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
irb(main):004:0> helper.document_path(@documents.last)
NoMethodError: undefined method `document_path' for #<ActionView::Base:0x0000010f44cf40>
from (irb):4
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/railties-3.0.9/lib/rails/commands/console.rb:44:in `start'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/railties-3.0.9/lib/rails/commands/console.rb:8:in `start'
from /opt/local/lib/ruby1.9/gems/1.9.1/gems/railties-3.0.9/lib/rails/commands.rb:23:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
irb(main):005:0>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment