This project is archived and is in readonly mode.
Router in Rails 3 pluralizes collection named routes twice
-
Santiago Pastorino
- State changed from new to invalid
You have to fix this in your application doing your own inflections. Thanks.
-
Juanma Cervera
Hi Santiago.
I don't know what you mean.
I already have an initializer with the inflections for the language of my app.ActiveSupport::Inflector.inflections do |inflect| inflect.plural( /$/, 'es') inflect.plural(/z$/i, 'ces') inflect.plural(/([aeiou])$/i, '\1s') inflect.singular(/s$/i, '') inflect.singular(/es$/i, '') inflect.singular(/ces$/i, 'z') inflect.singular(/([tj])es$/i, '\1e') endAnd it works great, for all the application, except in the routes, and only when I use the new router syntax.
Also works well when I use the old router syntax, and this make me think of a problem.Juanma Cervera
-
Andrew White
If you compare the deprecated mapper to the new mapper then you can see there's an extra call to pluralize which is causing the problem.
My Spanish isn't up to the task but if you adjust the first inflect.plural to not match words ending 'es' then that should fix your problem as invoking pluralize on English plural words doesn't double pluralize them.
-
gucki
I'm facing the same error, using a fresh rails project using latest beta4 and no custom inflections. Please see here:
#4857 Router in Rails 3 doesn't use inflections properly *really* -
javierm
My Spanish isn't up to the task but if you adjust the first inflect.plural to not match words ending 'es' then that should fix your problem
Hello, Andrew.
I'm spanish as well and am using similar inflection rules, so I've got the same problem.
Unfortunately, your suggestion isn't free of troubles. In spanish, there are words that are singular and end in "s", like "res", whose plural is "reses" (same rule as any other word ending in a consonant).
I know I can add irregular plurals, but then I guess that if we use them for regular plurals we miss the point of defining expressions about how to make plurals.
This bug is mark as "invalid", but I don't think it should be. "wontfix" maybe, but Rails is supposed to have rules such as "singular form for member path and plural form for collection path", and here it is creating "singular form for member path and plural of the plural for collection path", because of the extra call to pluralize that you mention.
Thanks!
-
javierm
Apparently it also happens with english words, even if I don't use any inflections.
The plural of "taxi" is "taxis", but the plural of "taxis" is "taxes". So if I generate a "taxi" scaffold, "taxis_path" is not generated, but "taxes_path" is.
Unfortunately I haven't been able to come with a valid test case. Test cases for taxes are already there, and adding test cases for taxis ends up in failure, but I think it fails because of a conflict with the already defined routes for taxes.
I hope you take this as "trying to help" instead of "spamming on that thing nobody cares about", cause that's my intention ;). If you don't want to fix it, hey, it's your app, you have your priorities.
-
javierm
- Title changed from Router in Rails 3 doesn't use inflections properly to Router in Rails 3 pluralizes collection named routes twice
I think I finally figured out where to write the test I wanted. I attach a failing test, patched against v3.0.0_RC (sorry, I couldn't get master to work; bundle failed).
The first assertion works, but the other two fail.
Thanks.
-
Andrew White
- State changed from invalid to open
- Assigned user set to Andrew White
- Importance changed from to Low
The problem with your test is that taxis (as in the minicab) doesn't have it's own rule - once you add the custom irregular inflection everything works out and it's unlikely you're going to be writing an app with deals with minicabs and surgery together. What we need is a test where two words are likely to be used together and their pluralization overlaps similar to taxi(s) and tax(is|es) - it doesn't matter if they're Spanish.
Anyway, it's really a good idea to get your inflections setup so that they are idempotent as you never know when you'll end up pluralizing an already pluralized word in your own code.
-
javierm
Hi, Andrew.
Didn't see your answer before, but in the meantime I've created a patch that makes the test pass and doesn't break any other tests (at least in action pack; couldn't test the whole suite):
-
javierm
What we need is a test where two words are likely to be used together and their pluralization overlaps similar to taxi(s) and tax(is|es) - it doesn't matter if they're Spanish.
I'm afraid I don't understand what you mean. Since I'm not sure we're talking about the same thing, I'll try to explain my problem.
The problem happens with almost any spanish word. The plural of "cliente" is "clientes". And grammar rules says that, if it existed, the plural of "clientes" would be "clienteses" (and the plural of "clienteses" would be "clienteseses", and so on), since words ending with a consonant make (usually) the plural with "-es",
And that's the original problem: applying spanish rules to the inflections made "clienteses_path" to be generated, instead of "clientes_path".
Hope it helps. Tell me if I'm understanding you wrong.
Thanks.
-
javierm
The patch is now applied in my fork:
http://github.com/javierv/rails/commit/41f3ccd2ca73f0029147ae613b7d...
-
Andrew White
- Milestone cleared.
- Tag set to rails 3.0, patch, resources, routing
Javier, I've taken your patch and expanded it a bit - don't worry you're still marked as the author.
Anyway the attached patch tests both the medical term and transport term and refactors the resource name methods a bit. The patch applies cleanly to master and stable.
-
javierm
Awesome! Thank you, Andrew.
It's ok if you figure as the author anyway. I wouldn't have come up with such a complete patch, after all.
-
Repository
- State changed from open to resolved
(from [3e871eee8048c0e11e270ae4fbcbe40226148c33]) Don't pluralize resource methods [#4704 Router in Rails 3 pluralizes collection named routes twice state:resolved]
Signed-off-by: Santiago Pastorino santiago@wyeworks.com
http://github.com/rails/rails/commit/3e871eee8048c0e11e270ae4fbcbe4... -
Repository
(from [12f7f7a714cd485ba7c1b272ce1d6dbbcfae23e1]) Don't pluralize resource methods [#4704 Router in Rails 3 pluralizes collection named routes twice state:resolved]
Signed-off-by: Santiago Pastorino santiago@wyeworks.com
http://github.com/rails/rails/commit/12f7f7a714cd485ba7c1b272ce1d6d...
