Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby on Rails: how to check pluralized and single form of names

I have created a model Anonymous with command

rails g model Anonymous section_id:integer aid:string fake:bool active:bool

but table name in the migration is called anonymous

class CreateAnonymous < ActiveRecord::Migration
  def change
    create_table :anonymous do |t|
      t.integer :section_id
      t.string :aid
      t.bool :fake
      t.bool :active

      t.timestamps
    end
  end
end

Am i right that pluralized form of Anonymous is Anomymous too ? (English is not my native language). How can i see what pluralized names Rails gives to my models ? Something like rake routes ?

like image 480
s9gf4ult Avatar asked Nov 06 '12 04:11

s9gf4ult


2 Answers

You can do this in the rails console.

$ "anonymous".pluralize
=> "anonymous" 

or another example where the plural word is different.

$ "cookie".pluralize
=> "cookies" 
like image 136
Robert B Avatar answered Sep 20 '22 02:09

Robert B


pluralize(count, singular, plural = nil) public

Attempts to pluralize the singular word unless count is 1. If plural is supplied, it will use that when count is > 1, otherwise it will use the Inflector to determine the plural form

Examples:

pluralize(1, 'person')
# => 1 person

pluralize(2, 'person')
# => 2 people

pluralize(0, 'person')
# => 0 people

for you

"anonymous".pluralize
like image 28
Dipak Panchal Avatar answered Sep 21 '22 02:09

Dipak Panchal