Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ruby on rails pluralization help? [duplicate]

Possible Duplicate:
How do I override rails naming conventions?

My app is gonna be in spanish. Say I want to scaffold generate actividad. the plural would be actividades so I want the table and the controller to be named that .... how can I do this?

like image 748
nacho10f Avatar asked Oct 28 '09 21:10

nacho10f


2 Answers

Put the following code in config/environment.rb:

Inflector.inflections do |inflect|
  inflect.irregular 'actividad', 'actividades'
end

Test the code in the console (script/console):

'actividad'.pluralize
'actividades'.singularize

More details can be found here: http://codeidol.com/other/rubyckbk/Web-Development-Ruby-on-Rails/Understanding-Pluralization-Rules/

like image 119
Kieran Hayes Avatar answered Nov 15 '22 06:11

Kieran Hayes


You can add your own pluralizations to Rails by adding inflections. Rails should have a file called inflections.rb under /config/initializers. You can add it there if it isn't. My file as an example (comments come from Rails):

# Add new inflection rules using the following format
# (all these examples are active by default):
# Inflector.inflections do |inflect|
#   inflect.plural /^(ox)$/i, '\1en'
#   inflect.singular /^(ox)en/i, '\1'
#   inflect.irregular 'person', 'people'
#   inflect.uncountable %w( fish sheep )
# end

ActiveSupport::Inflector.inflections do |inflect|
  inflect.plural(/rion$/ ,'ria') # criterion => criteria
  inflect.singular(/ria$/, 'rion') # criteria => criterion
end
like image 22
scottd Avatar answered Nov 15 '22 04:11

scottd