On May 22, 2005, at 4:19 AM, David Corbin wrote:> Is there any support for "overriding" the generated scripts? In
> one case, I''d
> like to generate an additional file, in one case, I''d like to put
a
> generated
> file in a different location, and in one case, I''d like to
actually
> affect
> the content of the generated code.
Sure, adapt one of the builtin generators to your needs. Copy the
files from the gem directory or from a svn checkout to ~/.rails/
generators. For example:
cd /path/to/svn/checkout
cp -r railties/lib/rails_generator/generators/components/model
~/.rails/generators/mymodel
Then alter your new mymodel generator as you like. Run it using
./script/generate mymodel Foo
just as you would with the builtin generators.
The generate script looks for builtins, gems ending in _generator,
user creations living in ~/.rails/generators, and application-
specific generators in RAILS_ROOT/scripts/generators. It searches
these sources from app -> user -> gem -> builtin, so you can even
create a generator with the same name as a builtin to override it.
This is a great way quickly roll code in your own style. Modifying
the scaffold generator is particularly rewarding..
Best,
jeremy