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.

Uncountable inflections lead to exception with Rails 3 scaffolding

#3930

On a vanila Rails 3 beta1 app as well as on edge, when you generate a scaffold based upon an uncountable word you'll get a routing error.

That's what I did:
rails g scaffold fish name:string

When going to http://localhost:3000/fish/new, I'll get:

ActionController::RoutingError in Fish#new
Showing (...)/app/views/fish/_form.html.erb where line 1 raised:
No route matches {:action=>"destroy", :controller=>"fish"}

Extracted source (around line 1):
1: <% form_for(@fish) do |f| %>

The same happens for sheep (which, like fish, obviously is included in the active support inflector defaults) or other uncountable words I put in the inflection initializer. I also get a warning when running the generator:
Plural version of the model detected, using singularized version. Override with --force-plural.

Adding that option fixes the warning, but not the generated code.

Reported by Christoph Olszowka · February 11th, 2010 @ 12:00 PM

State: resolved
Milestone: 3.0.2
Assigned to: José Valim José Valim
Importance: none

Activity

  1. Samuel Danielson
    Samuel Danielson

    I can confirm this bug. fish_url and fish_path will also raise

    No route matches {:action=>"destroy", :controller=>"fish"}
    

    The following...

    resources :fish, :singular => :fish_instance
    

    does not generate fish_instance_path and fish_instance_url as it did in Rails 2.3.5. Is there a work-around until this is fixed?

    February 23rd, 2010 @ 09:13 PM

  2. Jan De Poorter
    Jan De Poorter
    • Tag changed from inflections, rails3, routingerror, scaffold to inflections, rails3, routing, routingerror, scaffold

    This seems to be a routing issue rather then problems with scaffolding. I'm bumping into the same problem

    February 25th, 2010 @ 02:45 PM

  3. Jan De Poorter
    Jan De Poorter

    The attached patch should add _index to the uncountable resource (like it did in 2.3.5). This is only a partial solution to the scaffolding problem, but solves my problem with routes.

    February 25th, 2010 @ 03:25 PM

  4. Yehuda Katz (wycats)
  5. José Valim
    José Valim
    • Assigned user set to josh

    March 27th, 2010 @ 01:59 PM

  6. Rizwan Reza
    Rizwan Reza
    • State changed from new to resolved

    March 29th, 2010 @ 02:35 AM

  7. Rizwan Reza
  8. Throlkim
    Throlkim

    I'm experiencing this same problem on Rails 3 beta 4. I have the following route:

    resources :research
    

    I receive the following error:

    ActionController::RoutingError in Research#new
    No route matches {:action=>"destroy", :controller=>"research"}
    Extracted source (around line [#1](/projects/8994/tickets/1 "Ticket #1")):
    
    1: <%= form_for @research, :as => :research do |f| %>
    2:   <% if @research.errors.any? %>
    3:     <div id="error_explanation">
    4:       <h2><%= pluralize(@research.errors.count, "error") %> prohibited this research from being saved:</h2>
    

    Is there a way to resolve this, or is it still an ongoing bug?

    June 9th, 2010 @ 11:35 PM

  9. Neeraj Singh
    Neeraj Singh

    @Throlkim It works for me with latest master.

    rails generate scaffold research title:string
    rake db:migrate
    rails server
    # visit http://localhost:3000/researches
    

    I am able to visit index page and am able to create a new research.

    June 10th, 2010 @ 04:35 PM

  10. Throlkim
    Throlkim

    @Neeraj, Did you set it up as uncountable? My route is http://localhost:3000/research :) I'm running the latest master too, as of last night methinks.

    June 10th, 2010 @ 04:41 PM

  11. Christopher Redinger
    Christopher Redinger

    Definitely still broken. Followed the steps laid out in #4898 and see the same problem. The problem is that polymorphic_url is mapping to the :show action for that form_for, when it should be mapping to the :create.

    Possibly because it's matching /fish/:id, when it should be matching /fish/new?

    June 18th, 2010 @ 09:28 PM

  12. Andrew White
    Andrew White

    Okay, here's a patch that should fix this issue.

    June 19th, 2010 @ 10:38 PM

  13. José Valim
    José Valim
    • Milestone cleared.
    • State changed from resolved to open
    • Assigned user changed from josh to José Valim

    June 19th, 2010 @ 11:10 PM

  14. José Valim
    José Valim
    • State changed from open to committed

    June 19th, 2010 @ 11:20 PM

  15. José Valim
    José Valim
    • No changes were found…

    June 19th, 2010 @ 11:20 PM

  16. Repository
    Repository
    • State changed from committed to resolved

    (from [ed3f042e99949526f483d1f567e40031deea33d3]) Make polymorphic_url and scaffolding work with uncountable resources [#3930 state:resolved]

    Signed-off-by: José Valim jose.valim@gmail.com
    http://github.com/rails/rails/commit/ed3f042e99949526f483d1f567e400...

    June 19th, 2010 @ 11:21 PM

  17. Jeremy Kemper