This project is archived and is in readonly mode.

#4898 ✓duplicate
Jason Rudolph

Routing issue with 'uncountable' resources

Reported by Jason Rudolph | June 18th, 2010 @ 11:46 AM

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)

Comments and changes to this ticket

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>

Referenced by

Pages