Forum: Ruby on Rails pluralization issue? (taxes/taxis)

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
17fa7869b96bf7243280fe0c158b78d3?d=identicon&s=25 Michael Lascarides (mlas)
on 2006-04-12 22:53
Hi all,

Here's an odd one. I have a "Tax" model which is related via a habtm
relationship to a "Storefront" model. In my view_store rhtml file, I
have the line :

@storefront.taxes.each do |tax|

This line returns the following error:

NameError in Admin#view_store

Showing app/views/admin/view_store.rhtml where line #52 raised:

uninitialized constant Taxis

See that? "Taxes" has become "Taxis". Since I am not trying to attach a
Yellow Cab to my customers' orders, I don't want that. A search of the
whole Rails app turns up no instances of the string "taxi" anywhere.
Therefore I suspect an oddball pluralization.

From the console, "taxi".pluralize returns "taxis", and "tax".pluralize
returns "taxes", so they look right. Just to be safe, I redeclared those
plurals explicitly in my environment.rb. Still no dice.

I am at a loss, so I am throwing it out to y'all in the hopes someone
might have stumbled across this issue.

thanks,

Michael.
17fa7869b96bf7243280fe0c158b78d3?d=identicon&s=25 Michael Lascarides (mlas)
on 2006-04-13 00:11
Solved it!

> From the console, "taxi".pluralize returns "taxis", and "tax".pluralize
> returns "taxes", so they look right. Just to be safe, I redeclared those
> plurals explicitly in my environment.rb. Still no dice.

Apparently the singular -> plural and plural -> singular conversions are
not the same thing, so adding the singularize directives fixed the
problem:

Inflector.inflections do |inflect|
  inflect.plural 'tax', 'taxes'
  inflect.plural 'taxi', 'taxis'
  inflect.singular 'taxes', 'tax'
  inflect.singular 'taxis', 'taxi'
end

Rails must think that "taxi" is the singular of "taxes" by default.

- mL.
This topic is locked and can not be replied to.