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.

Router in Rails 3 doesn't use inflections properly *really*

#4857

Sry for the bad formatting, here we go again:


Test::Application.routes.draw do |map|
  resources :blogs
  resources :books
end


####

         GET    /blogs(.:format)          {:action=>"index", :controller=>"blogses"}
  blogses POST   /blogs(.:format)          {:action=>"create", :controller=>"blogses"}
 new_blog GET    /blogs/new(.:format)      {:action=>"new", :controller=>"blogses"}
          GET    /blogs/:id(.:format)      {:action=>"show", :controller=>"blogses"}
          PUT    /blogs/:id(.:format)      {:action=>"update", :controller=>"blogses"}
     blog DELETE /blogs/:id(.:format)      {:action=>"destroy", :controller=>"blogses"}
edit_blog GET    /blogs/:id/edit(.:format) {:action=>"edit", :controller=>"blogses"}
          GET    /books(.:format)          {:action=>"index", :controller=>"bookses"}
  bookses POST   /books(.:format)          {:action=>"create", :controller=>"bookses"}
 new_book GET    /books/new(.:format)      {:action=>"new", :controller=>"bookses"}
          GET    /books/:id(.:format)      {:action=>"show", :controller=>"bookses"}
          PUT    /books/:id(.:format)      {:action=>"update", :controller=>"bookses"}
     book DELETE /books/:id(.:format)      {:action=>"destroy", :controller=>"bookses"}
edit_book GET    /books/:id/edit(.:format) {:action=>"edit", :controller=>"bookses"}

Reported by gucki · June 14th, 2010 @ 12:08 PM

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

Activity

  1. gucki
    gucki
    • Tag set to rails3 beta4 inflections

    I'm using the latest beta4, created a brand new project using "rails new test" and hitting the same error as described in #4704 Router in Rails 3 pluralizes collection named routes twice. I'm not using any custom infections.

    Test::Application.routes.draw do |map|
    resources :blogs resources :books end

    ####

         GET    /blogs(.:format)          {:action=>"index", :controller=>"blogses"}
    

    blogses POST /blogs(.:format) {:action=>"create", :controller=>"blogses"} new_blog GET /blogs/new(.:format) {:action=>"new", :controller=>"blogses"}

          GET    /blogs/:id(.:format)      {:action=>"show", :controller=>"blogses"}
          PUT    /blogs/:id(.:format)      {:action=>"update", :controller=>"blogses"}
     blog DELETE /blogs/:id(.:format)      {:action=>"destroy", :controller=>"blogses"}
    

    edit_blog GET /blogs/:id/edit(.:format) {:action=>"edit", :controller=>"blogses"}

          GET    /books(.:format)          {:action=>"index", :controller=>"bookses"}
    

    bookses POST /books(.:format) {:action=>"create", :controller=>"bookses"} new_book GET /books/new(.:format) {:action=>"new", :controller=>"bookses"}

          GET    /books/:id(.:format)      {:action=>"show", :controller=>"bookses"}
          PUT    /books/:id(.:format)      {:action=>"update", :controller=>"bookses"}
     book DELETE /books/:id(.:format)      {:action=>"destroy", :controller=>"bookses"}
    

    edit_book GET /books/:id/edit(.:format) {:action=>"edit", :controller=>"bookses"}

    June 14th, 2010 @ 12:12 PM

  2. gucki
    gucki
    • Tag changed from rails3 beta4 inflections to rails3 beta4 inflections

    When I change the names to their singular form, the routes are correct. But I guess that's not the intended behavior?

    Test::Application.routes.draw do |map|
      resources :blog
      resources :book
    end
    
              GET    /blog(.:format)          {:action=>"index", :controller=>"blogs"}
        blogs POST   /blog(.:format)          {:action=>"create", :controller=>"blogs"}
     new_blog GET    /blog/new(.:format)      {:action=>"new", :controller=>"blogs"}
              GET    /blog/:id(.:format)      {:action=>"show", :controller=>"blogs"}
              PUT    /blog/:id(.:format)      {:action=>"update", :controller=>"blogs"}
         blog DELETE /blog/:id(.:format)      {:action=>"destroy", :controller=>"blogs"}
    edit_blog GET    /blog/:id/edit(.:format) {:action=>"edit", :controller=>"blogs"}
              GET    /book(.:format)          {:action=>"index", :controller=>"books"}
        books POST   /book(.:format)          {:action=>"create", :controller=>"books"}
     new_book GET    /book/new(.:format)      {:action=>"new", :controller=>"books"}
              GET    /book/:id(.:format)      {:action=>"show", :controller=>"books"}
              PUT    /book/:id(.:format)      {:action=>"update", :controller=>"books"}
         book DELETE /book/:id(.:format)      {:action=>"destroy", :controller=>"books"}
    edit_book GET    /book/:id/edit(.:format) {:action=>"edit", :controller=>"books"}
    

    June 14th, 2010 @ 12:27 PM

  3. Andrew White
    Andrew White

    You must have changed your inflections somewhere as doing "blogs".pluralize in a new app for me returns "blogs". Here's the default pluralization rules:

    [/k(?i)ine$/, "kine"]
    [/K(?i)ine$/, "Kine"]
    [/c(?i)ow$/, "kine"]
    [/C(?i)ow$/, "Kine"]
    [/(m)oves$/i, "\\1oves"]
    [/(m)ove$/i, "\\1oves"]
    [/(s)exes$/i, "\\1exes"]
    [/(s)ex$/i, "\\1exes"]
    [/(c)hildren$/i, "\\1hildren"]
    [/(c)hild$/i, "\\1hildren"]
    [/(m)en$/i, "\\1en"]
    [/(m)an$/i, "\\1en"]
    [/(p)eople$/i, "\\1eople"]
    [/(p)erson$/i, "\\1eople"]
    [/(quiz)$/i, "\\1zes"]
    [/^(ox)$/i, "\\1en"]
    [/([m|l])ouse$/i, "\\1ice"]
    [/(matr|vert|ind)(?:ix|ex)$/i, "\\1ices"]
    [/(x|ch|ss|sh)$/i, "\\1es"]
    [/([^aeiouy]|qu)y$/i, "\\1ies"]
    [/(hive)$/i, "\\1s"]
    [/(?:([^f])fe|([lr])f)$/i, "\\1\\2ves"]
    [/sis$/i, "ses"]
    [/([ti])um$/i, "\\1a"]
    [/(buffal|tomat)o$/i, "\\1oes"]
    [/(bu)s$/i, "\\1ses"]
    [/(alias|status)$/i, "\\1es"]
    [/(octop|vir)us$/i, "\\1i"]
    [/(ax|test)is$/i, "\\1es"]
    [/s$/i, "s"]
    [/$/, "s"]
    

    As you can see blogs and books would match the penultimate regexp which just replaces the last 's' with another 's'. Have you got any plugins or gems installed that might have changed things?

    June 14th, 2010 @ 12:58 PM

  4. gucki
    gucki

    Thanks for the hint. It seems that "dm-paperclip" is causing the troubles as it's working fine without this gem. I'll report the bug there, so this ticket can be closed. Thanks again! :)

    June 14th, 2010 @ 01:54 PM

  5. José Valim
    José Valim
    • State changed from new to invalid

    June 14th, 2010 @ 05:45 PM