This project is archived and is in readonly mode.

#4952 ✓invalid
krschacht (at gmail)

Incorrect pluralization, can't fix with inflectors

Reported by krschacht (at gmail) | June 24th, 2010 @ 05:21 AM

I just generated scaffolding for "Niche".

When I try loading: http://127.0.0.1:3000/niches

I get an error: undefined local variable or method new_niche_path

This surprised me so I checked "rake routes" and, indeed, the pluralization is wrong:

             GET    /niches(.:format)                {:action=>"index", :controller=>"niches"}
      niches POST   /niches(.:format)                {:action=>"create", :controller=>"niches"}
    new_nich GET    /niches/new(.:format)            {:action=>"new", :controller=>"niches"}
             GET    /niches/:id(.:format)            {:action=>"show", :controller=>"niches"}
             PUT    /niches/:id(.:format)            {:action=>"update", :controller=>"niches"}
        nich DELETE /niches/:id(.:format)            {:action=>"destroy", :controller=>"niches"}
   edit_nich GET    /niches/:id/edit(.:format)       {:action=>"edit", :controller=>"niches"}

I confirmed this by trying:

'niches'.singularize > yields 'nich' 'niche'.pluralize > yields 'niches'

To correct, I added a custom inflector:

ActiveSupport::Inflector.inflections do |inflect|
inflect.irregular 'niche', 'niches' end

However, this does not fix the core problem. In console, singularize and pluralize are now correct, but my routes are unchanged. It still is defining the route as "new_nich" rather than "new_niche".

My relevant line from route.rb is:

resources :niches

This seems like a bug to me. It seems like the auto-route generation from the "resources" method is not using the same inflectors that the rest of the app is.

Comments and changes to this ticket

  • Rohit Arondekar

    Rohit Arondekar June 24th, 2010 @ 06:19 AM

    Did you add the custom inflector code to config/initializers/inflections.rb ? If not please add it there and try again. Also do report back if it works.

  • Andrew White

    Andrew White June 24th, 2010 @ 11:36 AM

    Works for me:

    # config/initializers/inflections.rb
    ActiveSupport::Inflector.inflections do |inflect|
      inflect.irregular 'niche', 'niches'
    end
    

    produces:

    andyw$ rake routes
               GET    /niches(.:format)          {:controller=>"niches", :action=>"index"}
        niches POST   /niches(.:format)          {:controller=>"niches", :action=>"create"}
     new_niche GET    /niches/new(.:format)      {:controller=>"niches", :action=>"new"}
               GET    /niches/:id(.:format)      {:controller=>"niches", :action=>"show"}
               PUT    /niches/:id(.:format)      {:controller=>"niches", :action=>"update"}
         niche DELETE /niches/:id(.:format)      {:controller=>"niches", :action=>"destroy"}
    edit_niche GET    /niches/:id/edit(.:format) {:controller=>"niches", :action=>"edit"}
    
  • Rohit Arondekar

    Rohit Arondekar June 24th, 2010 @ 11:40 AM

    • State changed from “new” to “invalid”

    Yes, it should work. I suspect krschacht added the inflections in config/environment.rb or somewhere else. Closing ticket, if it's still a problem make a comment and I'll reopen.

  • Ryan Bigg

    Ryan Bigg October 9th, 2010 @ 10:02 PM

    • Importance changed from “” to “Low”

    Automatic cleanup of spam.

  • bingbing

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>

Pages