Roy P. wrote:
That sounds intriguing. Where would I find rails’ scaffold
generator? I wonder if I could just get in there & monkey w/the
arguments that are passed…
The existing generator is in:
(depending on your version of Rails - run “gem environment” to see where
your gems are).
Rails will look for generators in ~/.rails (on UNIX/MacOS - don’t know
about Windows) so if you wanted your generator to be called “funky”:
mkdir -p ~/.rails/generators/funky
mv scaffold_generator.rb funky_generator.rb
Then edit funky_generator.rb and replace the class name
ScaffoldGenerator with FunkyGenerator and also update the “banner”
Now, in any Rails application you can use:
script/generate funky MyModel field1:type1 field2:type2 …
and get the same results as the standard scaffold.
Now, update the USAGE file to be more relevant to your scaffolding and
update the contents of the template directory accordingly.
Note that the template files are run through ERb when scaffolding
happens, so ERb commands that need to remain will start with “<%%”.
That is, where you see “<%%”, this will get passed through as “<%” and
where you see “<%”, this will get evaluated and the result passed
Any processing you want to do for creating the scaffold and any files
you want/don’t want to create are specified in funky_generator.rb.
To make the generator available to all users, turn it into a gem and
install it in [GEM_HOME].