This project is archived and is in readonly mode.

#4857 ✓invalid
gucki

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

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

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

Comments and changes to this ticket

  • gucki

    gucki June 14th, 2010 @ 12:12 PM

    • 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 https://rails.lighthouseapp.com/projects/8994/tickets/4704. 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"}

  • gucki

    gucki June 14th, 2010 @ 12:27 PM

    • 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"}
    
  • Andrew White

    Andrew White June 14th, 2010 @ 12:58 PM

    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?

  • gucki

    gucki June 14th, 2010 @ 01:54 PM

    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! :)

  • José Valim

    José Valim June 14th, 2010 @ 05:45 PM

    • State changed from “new” to “invalid”

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>

People watching this ticket

Referenced by

Pages