diff options
Diffstat (limited to 'railties/lib/rails_generator/generators/components/model')
3 files changed, 10 insertions, 4 deletions
diff --git a/railties/lib/rails_generator/generators/components/model/USAGE b/railties/lib/rails_generator/generators/components/model/USAGE index d9efa7a000..b93cf73716 100644 --- a/railties/lib/rails_generator/generators/components/model/USAGE +++ b/railties/lib/rails_generator/generators/components/model/USAGE @@ -5,8 +5,9 @@ Description: should not be suffixed with 'Model'. As additional parameters, the generator will take attribute pairs described by name and type. These attributes will - be used to prepopulate the migration to create the table for the model and give you a set of predefined fixture. - 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 + 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 needed to start really working with the resource. The generator creates a model class in app/models, a test suite in test/unit, test fixtures in @@ -21,6 +22,6 @@ Examples: Fixtures: test/fixtures/accounts.yml Migration: db/migrate/XXX_add_accounts.rb - ./script/generate model post title:string created_on:date body:text published:boolean - + ./script/generate model post title:string body:text published:boolean + Creates post model with predefined attributes. diff --git a/railties/lib/rails_generator/generators/components/model/templates/fixtures.yml b/railties/lib/rails_generator/generators/components/model/templates/fixtures.yml index 6be3c81bee..eb3ab81ab8 100644 --- a/railties/lib/rails_generator/generators/components/model/templates/fixtures.yml +++ b/railties/lib/rails_generator/generators/components/model/templates/fixtures.yml @@ -4,8 +4,12 @@ one: <% for attribute in attributes -%> <%= attribute.name %>: <%= attribute.default %> <% end -%> + created_at: <%= Time.now.to_s(:db) %> + updated_at: <%= Time.now.to_s(:db) %> two: id: 2 <% for attribute in attributes -%> <%= attribute.name %>: <%= attribute.default %> <% end -%> + created_at: <%= Time.now.to_s(:db) %> + updated_at: <%= Time.now.to_s(:db) %> diff --git a/railties/lib/rails_generator/generators/components/model/templates/migration.rb b/railties/lib/rails_generator/generators/components/model/templates/migration.rb index cb1ddd399e..b42aa81262 100644 --- a/railties/lib/rails_generator/generators/components/model/templates/migration.rb +++ b/railties/lib/rails_generator/generators/components/model/templates/migration.rb @@ -4,6 +4,7 @@ class <%= migration_name %> < ActiveRecord::Migration <% for attribute in attributes -%> t.<%= attribute.type %> :<%= attribute.name %> <% end -%> + t.timestamps end end |