Forum: Ruby on Rails hen to pluck: script/generate mailer

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
2c1a10ad0cce0f73e11a2a558a69f97c?d=identicon&s=25 gcnovus (Guest)
on 2007-01-23 20:48
(Received via mailing list)
I've decided that I don't like that script/generate mailer puts the
mailer class in app/models.  Call me picky, but I just think app/models
is for models.  I'm not going to try to change the whole of rails just
for me, but I would like to be able to configure this.

First, I looked up the class that actually does the mailer generation.
This is rails_generator/components/mailer/mailer_generator.rb - it's
either in your gem or in vendor/rails/railties/... if you've frozen
your rails version.

The code is straightforward, though it does have the downside of not
being configurable in any way.  Ah, well, let's just try redefining the
method within the file script/generate.

This doesn't work.  After some investigation, I find that it's because
the includes in that file actually run the generation right after the
original MailerGenerator is defined, so my new definition doesn't get
applied until after the code is run.

The next try was defining my class (after the necessary includes) at
the top of script/generate, then freezing the class so that the later
includes wouldn't overwrite it.  This, of course, results in a
TypeError.  I could surround the later code in a begin...rescue
TypeError block, but I don't like gobbling up errors.

What ended up working was copying in the contents of the included
script/generate, and inserting my class definition between its includes
and its code.  This seemed awfully hackish.

Another solution would be to simply change the original code in
 I don't like this because (a) you musts have rails frozen, (b)
updating to a new version overwrites my changes, and (c) my code
shouldn't go in Rails' directory; it should go in my app somewhere
(preferably lib/, but I'd accept script/).

Yet another solution would be to define my own generator that inherited
from MailerGenerator and call that, but I would really prefer not to.
Other developers might not know about the new one.  Really, though, I
just want to be able to make Rails do what I want.  I'm all for default
behavior, but I really should be able to change it.

Anyone have any thoughts?
-g c novus
This topic is locked and can not be replied to.