This project is archived and is in readonly mode.

#5542 ✓wontfix

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

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

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.

der Flo

Comments and changes to this ticket

  • Andrew White

    Andrew White September 3rd, 2010 @ 11:18 AM

    • 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 )
  • der_flo

    der_flo September 30th, 2010 @ 03:58 PM

    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
        class TestController < ApplicationController

      def index
        render :text =&gt; polymorphic_url(Seafood::Fish)

    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>
    Do you see the problem? Or is it an inconsistency?
    Thanks again!

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=""></a>

People watching this ticket