Some great shortcuts for script generation. I always try to start by building scaffold for any new entity, then remove the scaffold as needed, leaving only the pieces of the scaffold which I need.
to generate a new model:
script/generate scaffold Person age:integer first:string last:string some_list_id:integer
* This will generate models, controllers, migrations & tests. ALWAYS USE THE SINGULAR when using script/generate.
* Be sure to spell the complete word integer, if you mistakenly shorten it to abbreviated form “int” the generate command will look like it has worked, but migration won’t execute.
If you make a mistake try
script/destroy (model name)
to add a field to an existing model
script/generate migration add_address_to_person address:string
to add a foreign key to an existing model
script/generate migration add_state_id_to_person state_id:integer