This project is archived and is in readonly mode.
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.
Thanks,
der Flo
Comments and changes to this ticket
-
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 ) end
-
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 ...</code>
class TestController < ApplicationController
def index render :text => 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=>"create", :controller=>"seafood/fish"} new_seafood_fish GET /seafood/fish/new(.:format) {:action=>"new", :controller=>"seafood/fish"} edit_seafood_fish GET /seafood/fish/:id/edit(.:format) {:action=>"edit", :controller=>"seafood/fish"} seafood_fish GET /seafood/fish/:id(.:format) {:action=>"show", :controller=>"seafood/fish"} seafood_fish PUT /seafood/fish/:id(.:format) {:action=>"update", :controller=>"seafood/fish"} seafood_fish DELETE /seafood/fish/:id(.:format) {:action=>"destroy", :controller=>"seafood/fish"}</code>
But calling our action
/test/index
gives us the following error:undefined method
seafood_fishes_url' for #<TestController:0x9100848></code> </pre>
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="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>