Browse files

Add few information on the field types

  • Loading branch information...
robin850 committed Jul 4, 2012
1 parent b5a2f24 commit 2f6004de6e692da81237a4d978b273acfbc9f396
Showing with 49 additions and 0 deletions.
  1. +49 −0 railties/lib/rails/generators/rails/model/USAGE
@@ -19,6 +19,55 @@ Description:
then the generator will create a module with a table_name_prefix method
to prefix the model's table name with the module name (e.g. admin_account)
+Available field types:
+ Just after the field name you can specify a type like text or boolean.
+ It will generate the column with the associated SQL type. For instance:
+ `rails generate model post title:string body:text`
+ will generate a title column with a varchar type and a body column with a text
+ type. You can use the following types:
+ integer
+ primary_key
+ decimal
+ float
+ boolean
+ binary
+ string
+ text
+ date
+ time
+ datetime
+ timestamp
+ You can also consider `references` as a kind of type. For instance, if you run:
+ `rails generate model photo title:string album:references`
+ It will generate an album_id column. You should generate this kind of fields when
+ you will use a `belongs_to` association for instance. `references` also support
+ the polymorphism, you could enable the polymorphism like this:
+ `rails generate model product supplier:references{polymorphic}`
+ You can also specify some options just after the field type. You can use the
+ following options:
+ limit Set the maximum size of the field giving a number between curly braces
+ default Set a default value for the field
+ precision Defines the precision for the decimal fields
+ scale Defines the scale for the decimal fields
+ uniq Defines the field values as unique
+ index Will add an index on the field
+ Examples:
+ `rails generate model user pseudo:string{30}`
+ `rails generate model user pseudo:string:uniq`
`rails generate model account`

0 comments on commit 2f6004d

Please sign in to comment.