Instance Eval

Programming, Linux/Unix/OSX, etc.

Removing Action Mailer From a Rails App

A short note & reminder to self about how to remove Action Mailer from a Rails app that doesn’t need it:

  • remove its railtie require require "action_mailer/railtie" from config/application.rb
  • remove all the configuration options referring to config.action_mailer from all the config/environments files (by default development.rb, production.rb and test.rb)

The second step is important; if you forget it, the app won’t start because the config.action_mailer references in the configuration files will fail.

If you have require 'rails/all' at the top of application.rb instead of individual railtie requires, you can substitute it with:

1
2
3
4
require "action_controller/railtie"
require "action_mailer/railtie"  # the one to remove
require "sprockets/railtie"
require "rails/test_unit/railtie"

Then in this case you can remove the action_mailer one.

You can remove other unnecessary parts in a similar fashion, but they may have a different set of dependencies in gems, configuration files, etc., especially in a legacy app that has accumulated various stuff over time. It’s also possible to dig even deeper and pluck out unnecessary parts from the Rack middleware stack etc., but not going into those in this post.

When starting a fresh new app, remember to check the options for the rails new command, there are several which will skip installing specified unneeded parts; see rails new --help.

Comments