How to Disable Pluralization

Hi,

First, I am new at Ruby on Rails. When using scaffolding feature,
rails pluralize some automatically generated files’ names, like
controller names, view names and helper names. What I want is to
disable this pluralization. For example, I want the contoller name of
model ‘Post’ to be ‘post_controller.rb’ instead of
‘posts_controller.rb’.

Thanks.

You could just change the names of the files, but I think you’d also
have to
make changes elsewhere (e.g., routes.rb). Why go against the convention,
though? Doing so will likely cause you more work and, at least
initially, be
slightly confusing to others who read your code.
Regards,
Craig


Craig D.
Mutually Human Software

You can rewrite the inflections using
ActiveSupport::Inflector.inflections (http://api.rubyonrails.org/
classes/ActiveSupport/Inflector/Inflections.html) and do something
like mapping the plural of all words to the same word.

Regards.

Franco C…

Before you do anything extreme, try this (example from previous post).

script/generate scaffold Equipment name:string kind:string

Then see what happens when you go: http://localhost:3000/equipment/new

Equipment is a word that behaves just as you’ld like with singular
(equipment) == plural(equipment).

You’re going to need more than just inflections to make this puppy
work.

On Sat, Jul 18, 2009 at 3:24 AM, harun[email protected] wrote:

Hi,

First, I am new at Ruby on Rails. When using scaffolding feature,
rails pluralize some automatically generated files’ names, like
controller names, view names and helper names. What I want is to
disable this pluralization. For example, I want the contoller name of
model ‘Post’ to be ‘post_controller.rb’ instead of
‘posts_controller.rb’.

If you want to gain any proficiency with Rails, I’d urge you to resist
the instinct to do things like this, and go with the flow.

A lot of Rails is following the frameworks conventions, and
pluralization is one of those. If you do you’ll find things much
easier in the long run.

If you don’t you’ll find yourself working much too hard in the long run.


Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale

Rick Denatale wrote:

If you want to gain any proficiency with Rails, I’d urge you to resist
the instinct to do things like this, and go with the flow.

I completely agree with this philosophy. If you can’t abide following
conventions, then maybe Rails isn’t the right choice for you. That being
said; if you can find a way to relinquish stubbornness, and concentrate
on the things that make your application unique, then you might just
find that the established conventions eliminate a lot of the decisions
that are common to every application.

Otherwise, you’ll end up spending all your time fighting against the
framework instead of concentrating on making your application great.

Rick Denatale wrote:

If you want to gain any proficiency with Rails, I’d urge you to resist
the instinct to do things like this, and go with the flow.

+10 for Rick’s opinion and Robert’s second… you’re starting down a
very slippery slope, to say nothing of the fact that altering the
default behaviors will just make it that much harder for other people
who work with the framework to understand your code, which will just
appear like an abberation.

I also agree with that, I want to make my point cleaner. English is
not my mother language (if you don’t figure it out yet), and
programming in Rails is often a pleasure, but if you want to program
in Spanish for example, the pluralization don’t work. For example the
plural of Ciudad (City) is Ciudades, but is pluralized as Ciudads
(awful). I asume that the question was for one problem like this, i
don’t “support” not follow the conventions either.

Regards.

Franco C…

On Wed, Jul 22, 2009 at 7:37 AM, Franco C.[email protected]
wrote:

I also agree with that, I want to make my point cleaner. English is
not my mother language (if you don’t figure it out yet), and
programming in Rails is often a pleasure, but if you want to program
in Spanish for example, the pluralization don’t work. For example the
plural of Ciudad (City) is Ciudades, but is pluralized as Ciudads
(awful). I asume that the question was for one problem like this, i
don’t “support” not follow the conventions either.

But you can teach the inflector to handle this by giving proper
pluralizations of words.

It would be nice it there was support to do this en masse for a given
language but it’s not easy.

But doing it for the specific words which need to be handled in a
given app (mostly model names) is certainly possible in most cases,
and shouldn’t require taking the approach of disabling pluralization.


Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale

Rails main motto is “convention over configuration”
why do you want to go against the flow. in that case
you have to face lots of problem in future. but you can
do that by changing the inflection or the generation system of ROR