O'Reilly logo

Crafting Rails 4 Applications, 2nd Edition by José Valim

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Customizing Rails Generators

With our template handler in hand and rendering multipart emails, the final step is to create a generator for our plug-in. Our generator will hook into Rails’s mailer generator and configure it to create merb instead of erb templates.

Rails generators provide hooks to allow other generators to extend and customize the generated code. A quick look at the mailer generator in the Rails source code reveals the hooks it provides:

rails/railties/lib/rails/generators/rails/mailer/mailer_generator.rb
 
module​ Rails
 
module​ Generators
 
class​ MailerGenerator < NamedBase
 
source_root File.expand_path(​"../templates"​, __FILE__)
 
argument :actions, type: :array,
 
default: [], banner: ​"method method"
 
check_class_collision ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required