Editing the migration template

Hello Dominic

To myself.

That's easy: http://rails.techno-weenie.net/question/2006/3/26/change_indentation_of_auto_generated_rails_code

Dominic Son wrote: > Hi. I'd like to edit the generated template in AR where tables are > created. > > for example, this file is created when generating a new model or > migration: > > class CreateModel < ActiveRecord::Migration > def self.up > create_table :models do |t| > # t.column :type, > > I'd like to edit the above so it'll generate this: > > class CreateModel < ActiveRecord::Migration > def self.up > create_table :models do |t| > # t.column :type, :limit => , :null => false > > Can someone point me in the right direction?

Don't modify files in Rails gems directory, it's ugly !

Write your own generator, it is also easy. The template you want to change is rails-xx//lib/rails_generator/generators/components/model/templates/migration.rb

so you have to make your own model generator, a slightly modified version :

go to your Rails Root app. cd lib mkdir generators cd generators cp -Rv PATH_TO_RAILS/lib/rails_generator/generators/components/model/ . mv model my_model cd my_model mv model_generator my_model_generator (modify templates/migration.rb or any other templates files if you like)

So your my_model generator is in RAILS_ROOT/lib/generators and you just have to do a :

script/generate my_model Foo

that you generated files exactly as you want.

Note that if you want your another rails apps to benefit from that generator, put it instead in ~/.rails/generators

If you upgrade Rails, it will still work (provided Generator API isn't changed !)

   -- Jean-Fran├žois.