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.

Strange pluralize and routing

#2046

Steps to reproduce:

$ rails test
$ cd test
$ ./script/generate scaffold tax
$ rake db:migrate

Target browser to /taxes/, Get

undefined local variable or method new_tax_path'

Lets see routes

$ rake routes

               taxes GET    /taxes
     formatted_taxes GET    /taxes.:format                   
                     POST   /taxes                           
                     POST   /taxes.:format                   
           new_taxis GET    /taxes/new                       
 formatted_new_taxis GET    /taxes/new.:format               
          edit_taxis GET    /taxes/:id/edit                  
formatted_edit_taxis GET    /taxes/:id/edit.:format          
               taxis GET    /taxes/:id                       
     formatted_taxis GET    /taxes/:id.:format               
                     PUT    /taxes/:id                       
                     PUT    /taxes/:id.:format               
                     DELETE /taxes/:id                       
                     DELETE /taxes/:id.:format               
                            /:controller/:action/:id         
                            /:controller/:action/:id.:format 

Its strange pluralize...

Next I've tryed to replace links to taxis. But <%= link_to 'Back', taxis_path %> called from /taxes/1 return /taxes/1

Reported by Sergey Kish · February 22nd, 2009 @ 09:26 PM

State: wontfix
Milestone: 2.x
Assigned to: Jeremy Kemper Jeremy Kemper
Importance: Low

Activity

  1. Sergey Kish
    Sergey Kish
    • Title changed from Strange pluralize and routing to prevent if can't fix

    If bug cannot be fixed (or you think it is not bug) maybe add warning to ./generate/controller?

    February 22nd, 2009 @ 09:31 PM

  2. Sergey Kish
    Sergey Kish
    • Title changed from prevent if can't fix to Strange pluralize and routing

    Sorry it has changed the title, I want only comment title.

    February 22nd, 2009 @ 09:33 PM

  3. CancelProfileIsBroken
    CancelProfileIsBroken

    Still a problem in RC2, though the routes have changed a bit:

    
    Phoenix ~/scratch/depot  $ rake routes
    (in /Users/mike/scratch/depot)
         taxes GET    /taxes(.:format)                   {:action=>"index", :controller=>"taxes"}
               POST   /taxes(.:format)                   {:action=>"create", :controller=>"taxes"}
     new_taxis GET    /taxes/new(.:format)               {:action=>"new", :controller=>"taxes"}
    edit_taxis GET    /taxes/:id/edit(.:format)          {:action=>"edit", :controller=>"taxes"}
         taxis GET    /taxes/:id(.:format)               {:action=>"show", :controller=>"taxes"}
               PUT    /taxes/:id(.:format)               {:action=>"update", :controller=>"taxes"}
               DELETE /taxes/:id(.:format)               {:action=>"destroy", :controller=>"taxes"}
                      /:controller/:action/:id           
                      /:controller/:action/:id(.:format) 
    

    The underlying issue is:

    "tax".pluralize.singularize => "taxis"

    The generator uses the original singular name fed in when building views and controllers. But the routing code initializes the singular name by singularizing the name in the map.resources call. Hence the mismatch.

    March 8th, 2009 @ 12:05 PM

  4. CancelProfileIsBroken
    CancelProfileIsBroken
    • State changed from new to wontfix

    Changing this behavior would require a major upheaval in the source, and you can get the right routes by supplying your own custom inflectors to handle "tax" <=> "taxes".

    March 8th, 2009 @ 12:37 PM

  5. Sergey Kish
    Sergey Kish

    There is even simple decision - use another name. But at first I need to know that will have troubles with current choice.

    Rails already show a note on using singularized name $ ./script/generate scaffold prices test:string

     warning  Plural version of the model detected, using singularized versi
    
    

    on. Override with --force-plural.

    It is few lines in /lib/rails_generator/generators/components/scaffold/scaffold_generator.rb

    def initialize(runtime_args, runtime_options = {})

    super
    
    if @name == @name.pluralize && !options[:force_plural]
      logger.warning "Plural version of the model detected, using singularized version.  Override with --force-plural."
      @name = @name.singularize
    end
    
    

    Maybe add note too?

    For example

    if @name != @name.pluralize.singularize
      logger.warning "Attention you will get troubles this such name. Get another please."
    end
    
    

    Or even

    if @name != @name.pluralize.singularize
      logger.warning "\033[01;31mAttention you will get troubles this such name. Get another please.\033[00m"
    end
    
    

    I've attached the diff to generators file.

    March 8th, 2009 @ 03:57 PM

  6. CancelProfileIsBroken
    CancelProfileIsBroken
    • State changed from wontfix to open

    Seems a reasonable suggestion, as several people have hit this.

    March 8th, 2009 @ 04:03 PM

  7. Sam Ruby
    Sam Ruby

    I just hit this too. In addition to the warning, I'd suggest adding "tax" to the list of irregular inflections.

    April 15th, 2009 @ 02:47 PM

  8. Rishav Rastogi
    Rishav Rastogi
    • Assigned user set to Ryan Bigg

    Tax => Taxes works fine in 2.3.5.

    But I noticed, that there is no warning when using plural names for models though

      ./script/generate model prices 
    

    No longer throws any warnings.

    April 11th, 2010 @ 11:29 PM

  9. Ryan Bigg
    Ryan Bigg

    I can duplicate this on 2.3.5. Rishav, how did you test this?

    April 12th, 2010 @ 12:46 AM

  10. Ryan Bigg
    Ryan Bigg

    Here's a patch to fix this.

    April 12th, 2010 @ 12:51 AM

  11. Santiago Pastorino
    Santiago Pastorino
    • Tag changed from routing error, pluralize, routing to routing error, 2.3.x, 3.0.0.beta, patch, pluralize, routing
    • Assigned user changed from Ryan Bigg to Jeremy Kemper

    I'm with Sam Ruby so patches provided to 2-3-stable and master

    April 12th, 2010 @ 12:56 AM

  12. Yaroslav Markin
    Yaroslav Markin

    So what about #2399 Incorrect inflectors for 'business' or '*ness' and "Rails has a longstanding policy of not taking further inflector patches. Use an initializer in your application instead"?

    April 12th, 2010 @ 01:04 AM

  13. Ryan Bigg
    Ryan Bigg

    Santiago, why does inflection3 comment out a line? Also, could you please provide tests with your patches? Thanks.

    April 12th, 2010 @ 01:09 AM

  14. Santiago Pastorino
    Santiago Pastorino

    Yes you're right Ryan i was trying things and forgot to uncomment this line also i was a bit lazy and did things wrong, ;).
    Uploading again.

    April 12th, 2010 @ 01:25 AM

  15. Santiago Pastorino
  16. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to wontfix

    Santiago Pastorino: why we don't fix inflection issues?

    David Heinemeier Hansson:
    1) because there are many, many more unlikely-to-be-used irregular inflections that we'd then have to do
    2) because changing some of the existing rules might break applications that depend on the old behavior
    3) because it's so easy to add your own inflections

    April 12th, 2010 @ 01:59 AM

  17. Ryan Bigg
    Ryan Bigg
    • Tag cleared.
    • Importance changed from to Low

    Automatic cleanup of spam.

    October 9th, 2010 @ 09:47 PM