Skip to Main Content
Crafting Rails 4 Applications, 2nd Edition
book

Crafting Rails 4 Applications, 2nd Edition

by Jose Valim
November 2013
Intermediate to advanced content levelIntermediate to advanced
200 pages
4h 31m
English
Pragmatic Bookshelf
Content preview from Crafting Rails 4 Applications, 2nd Edition

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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Rails 4 in Action

Rails 4 in Action

Yehuda Katz, Rebecca Skinner, Stephen Klabnik, Ryan Bigg
Rails: Novice to Ninja, 3rd Edition

Rails: Novice to Ninja, 3rd Edition

Glenn Goodrich, Patrick Lenz
Sinatra: Up and Running

Sinatra: Up and Running

Alan Harris, Konstantin Haase
Mastering Ruby Closures

Mastering Ruby Closures

Benjamin Tan Wei Hao

Publisher Resources

ISBN: 9781941222331Errata