Customizing generators - extend rails generators vs copy the

Hi,

I’ve got some generator tweaks I’d like to make (e.g. controllers, model
&
scaffold) but I’m wondering whether I should either (a) take a copy and
modify the existing controllers or (b) try to extend the existing
generators
so as to better leverage rails upgrades in the future.

Does anyone know whether (b) is possible? That is, is there a way to
make
changes/additions to the custom rails generators in a way that won’t
break
for future rails releases? Or is this difficult or not possible and I
should really just create my own generators (based on the rails ones as
a
starting point).

Tks
Greg

Greg H. <[email protected]…> writes:

Hi,I’ve got some generator tweaks I’d like to make (e.g. controllers, model &
scaffold) but I’m wondering whether I should either (a) take a copy and
modify
the existing controllers or (b) try to extend the existing generators so
as to
better leverage rails upgrades in the future.
Does anyone know whether (b) is possible? That is, is there a way to make
changes/additions to the custom rails generators in a way that won’t
break for
future rails releases? Or is this difficult or not possible and I
should really
just create my own generators (based on the rails ones as a starting
point).

Personally I’d go with taking a copy, otherwise there’s no way to tell
whether
the changes being made are going to have aneffect on the lines you’re
adding.

On the other hand, it’s definitely possible to call a generate script
from your
generate script, using m.dependency in your generate script, for example

m.dependency ‘model’, [@model_name] # adds or removes a model depending
on
# whether this script is being called with create or destroy

Gareth

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs