When you have an uncountable resource (e.g., fish, sheep), Rails
is unable to generate a form for that resource. Given a simple form
for that resource ...
<%= form_for(@sheep) do |f| %>
<% end %>
When Rails attempts to render the form, it yields the following
error:
ActionView::Template::Error: No route matches {:action=>"destroy", :controller=>"sheep"}
I've tested and verified that this issue exists with Rails 3,
Beta 4 and edge Rails as of June 18 (SHA a55d832).
The following commands will recreate the issue from scratch:
rails new farm
cd farm
./script/rails generate scaffold sheep name:string
rake db:migrate
rake test:functionals
The (summarized) output is as follows:
[farm] ./script/rails generate scaffold sheep name:string
Plural version of the model detected, using singularized version. Override with --force-plural.
invoke active_record
create db/migrate/20100618103202_create_sheep.rb
create app/models/sheep.rb
invoke test_unit
create test/unit/sheep_test.rb
create test/fixtures/sheep.yml
route resources :sheep
invoke scaffold_controller
create app/controllers/sheep_controller.rb
invoke erb
create app/views/sheep
create app/views/sheep/index.html.erb
...
[farm] rake db:migrate
...
[farm] rake test:functionals
(in /Users/jason/tmp/farm)
Loaded suite /Users/jason/.gem/ruby/1.8.7/gems/rake-0.8.7/lib/rake/rake_test_loader
Started
....E..
Finished in 0.090014 seconds.
1) Error:
test_should_get_new(SheepControllerTest):
ActionView::Template::Error: No route matches {:action=>"destroy", :controller=>"sheep"}
app/views/sheep/_form.html.erb:1
app/views/sheep/new.html.erb:3
app/controllers/sheep_controller.rb:29:in `new'
/test/functional/sheep_controller_test.rb:15:in `test_should_get_new'
7 tests, 9 assertions, 0 failures, 1 errors
rake aborted!
Command failed with status (1): [/Users/jason/.ruby_versions/ruby-enterpris...]
(See full trace by running task with --trace)