Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Routing issue with 'uncountable' resources

#4898

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)

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

State: duplicate
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Andrew White
  2. Christopher Redinger
    Christopher Redinger

    Andrew,
    It's a duplicate, but that ticket is closed. Jason's ticket lays out how to reproduce the error still, so either that ticket needs to be reopened, or this one needs to be handled for 3.0.

    June 18th, 2010 @ 10:09 PM

  3. Andrew White
    Andrew White

    Christoper, I've added a patch to #3930 - check it out and see if it fixes your problem.

    June 19th, 2010 @ 10:39 PM

  4. Santiago Pastorino
    Santiago Pastorino
    • State changed from new to duplicate

    June 20th, 2010 @ 12:41 AM

  5. Christopher Redinger
    Christopher Redinger

    Andrew - confirmed. That patch fixes it. Thanks!

    June 20th, 2010 @ 02:28 AM