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.

Incorrect pluralization, can't fix with inflectors

#4952

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.

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

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

Activity

  1. Rohit Arondekar
    Rohit Arondekar

    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.

    June 24th, 2010 @ 06:19 AM

  2. Andrew White
    Andrew White

    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"}
    

    June 24th, 2010 @ 11:36 AM

  3. Rohit Arondekar
    Rohit Arondekar
    • 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.

    June 24th, 2010 @ 11:40 AM

  4. Ryan Bigg
    Ryan Bigg
    • Importance changed from to Low

    Automatic cleanup of spam.

    October 9th, 2010 @ 10:02 PM

  5. bingbing