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.

Namespaced models: ActiveModel::Name uses ActiveSupport::Inflector incorrectly?

#5542

When working with namespaced models, ActiveModel::Name seems to use ActiveSupport::Inflector not correct.

@singular = ActiveSupport::Inflector.underscore(self).tr('/', '_').freeze
@plural = ActiveSupport::Inflector.pluralize(@singular).freeze

Suppose self is something like Seafood::Fish, @singular results in 'seafood_fish' and @plural in 'seafood_fishs'.
But @plural should also be 'seafood_fish', because 'fish' is defined as uncountable.

Do you agree, that this is an error? If yes, I could try to create a patch.

Thanks,
der Flo

Reported by der_flo · September 3rd, 2010 @ 10:01 AM

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

Activity

  1. Andrew White
    Andrew White
    • State changed from new to wontfix
    • Importance changed from to Low

    You need to add seafood_fish to your uncountable inflections:

    # config/initializers/inflections.rb
    ActiveSupport::Inflector.inflections do |inflect|
      inflect.uncountable %w( seafood_fish )
    end
    

    September 3rd, 2010 @ 11:18 AM

  2. der_flo
    der_flo

    The problem is that methods like polymorphic_url internally use the Inflector in the way I described, but the router handles it differently. I want to give an example:

        rvm 1.9.2
        rails new testapp
        cd testapp
        rails generate scaffold Seafood::Fish name:string
        rails generate controller test index
    

    config/routes.rb (generated):

        ...

    namespace :seafood do resources :fish end
    ...</code>
    
    
    
    
    app/controllers/test_controller.rb:
        class TestController < ApplicationController

      def index
        render :text =&gt; polymorphic_url(Seafood::Fish)
      end
    end</code>
    
    
    
    

    See what rake routes shows:

        seafood_fish_index GET    /seafood/fish(.:format)          {:action=>"index", :controller=>"seafood/fish"}

    seafood_fish_index POST   /seafood/fish(.:format)          {:action=&gt;&quot;create&quot;, :controller=&gt;&quot;seafood/fish&quot;}
      new_seafood_fish GET    /seafood/fish/new(.:format)      {:action=&gt;&quot;new&quot;, :controller=&gt;&quot;seafood/fish&quot;}
     edit_seafood_fish GET    /seafood/fish/:id/edit(.:format) {:action=&gt;&quot;edit&quot;, :controller=&gt;&quot;seafood/fish&quot;}
          seafood_fish GET    /seafood/fish/:id(.:format)      {:action=&gt;&quot;show&quot;, :controller=&gt;&quot;seafood/fish&quot;}
          seafood_fish PUT    /seafood/fish/:id(.:format)      {:action=&gt;&quot;update&quot;, :controller=&gt;&quot;seafood/fish&quot;}
          seafood_fish DELETE /seafood/fish/:id(.:format)      {:action=&gt;&quot;destroy&quot;, :controller=&gt;&quot;seafood/fish&quot;}</code>
    
    
    
    

    But calling our action /test/index gives us the following error:

        undefined method seafood_fishes_url' for #&lt;TestController:0x9100848&gt;</code>
    </pre>
    
    
    Do you see the problem? Or is it an inconsistency?
    Thanks again!

    September 30th, 2010 @ 03:58 PM