USAGE 1.3 KB
Newer Older
1 2 3
Description:
    The model generator creates stubs for a new model.

4 5
    The generator takes a model name as its argument.  The model name may be given in CamelCase or under_score and
    should not be suffixed with 'Model'.
6

7
    As additional parameters, the generator will take attribute pairs described by name and type. These attributes will
8 9 10
    be used to prepopulate the migration to create the table for the model and give you a set of predefined fixture.  By
    default, created_at and updated_at timestamps are added to migration for you, so you needn't specify them by hand.
    You don't have to think up all attributes up front, but it's a good idea of adding just the baseline of what's
11
    needed to start really working with the resource.
12

13 14
    The generator creates a model class in app/models, a test suite in test/unit, test fixtures in
    test/fixtures/singular_name.yml, and a migration in db/migrate.
15

16 17
Examples:
    ./script/generate model account
18

19 20 21 22 23 24
        This will create an Account model:
            Model:      app/models/account.rb
            Test:       test/unit/account_test.rb
            Fixtures:   test/fixtures/accounts.yml
            Migration:  db/migrate/XXX_add_accounts.rb

25 26
    ./script/generate model post title:string body:text published:boolean

27
        Creates post model with predefined attributes.