Ruby on Rails
HowToTweakThePluralizationRules (Version #15)

If you use another language to name your model/controller/tables, how can you tweak the pluralization rules so that the overall Rails system behaves like you are used to?

You could open the inflector (as suggested below), but you can easily add rules in Rails by changing the file app/config/environment.rb.

Another suggestion is to simply call the

set_table_name
method in your model


class Modulgruppe < ActiveRecord::Base
    set_table_name 'modulgruppen'

    belongs_to :veranstaltung
	
end

but this only refers to the actual table name you are using in the DB. What if you want to REALLY change the pluralization rules so that you can write with correct pluralization in every place?


class Veranstaltung < ActiveRecord::Base

    #should be able to write
    has_many :modulgruppen
    # instead of enlish plural
    has_many :modulgruppes
	
end

Write you own singular_rules and plural_rules

The inflector (which is a part of ActiveSupport, Inflector API reference) has two methods that contain the rules for (english) pluralization and singularization. Thanks to the nature of Ruby, the Inflector class can be opened up, and those two methods can be re-defined to return an alternate set of rules that could provide for pluralization in another language.

See Also: HowToUseLegacySchemas
See also: InflectorInCSharp

category: OpenQuestion

If you use another language to name your model/controller/tables, how can you tweak the pluralization rules so that the overall Rails system behaves like you are used to?

You could open the inflector (as suggested below), but you can easily add rules in Rails by changing the file app/config/environment.rb.

Another suggestion is to simply call the

set_table_name
method in your model


class Modulgruppe < ActiveRecord::Base
    set_table_name 'modulgruppen'

    belongs_to :veranstaltung
	
end

but this only refers to the actual table name you are using in the DB. What if you want to REALLY change the pluralization rules so that you can write with correct pluralization in every place?


class Veranstaltung < ActiveRecord::Base

    #should be able to write
    has_many :modulgruppen
    # instead of enlish plural
    has_many :modulgruppes
	
end

Write you own singular_rules and plural_rules

The inflector (which is a part of ActiveSupport, Inflector API reference) has two methods that contain the rules for (english) pluralization and singularization. Thanks to the nature of Ruby, the Inflector class can be opened up, and those two methods can be re-defined to return an alternate set of rules that could provide for pluralization in another language.

See Also: HowToUseLegacySchemas
See also: InflectorInCSharp

category: OpenQuestion