Skip to content

Commit 42e9eed

Browse files
committed
Prevent ActionMailer initializer from triggering load of ActionMailer
the after_initialize block has been changed to use the configuration from `config.action_mailer` rather than `ActionMailer::Base` so that action mailer is not loaded before it is necessary. the mailer preview routes setup have been moved out of an `on_load(:action_mailer)` block.
1 parent 37f32c0 commit 42e9eed

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

actionmailer/lib/action_mailer/railtie.rb

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,6 @@ class Railtie < Rails::Railtie # :nodoc:
4545

4646
options.each { |k,v| send("#{k}=", v) }
4747

48-
if options.show_previews
49-
app.routes.prepend do
50-
get '/rails/mailers' => "rails/mailers#index", internal: true
51-
get '/rails/mailers/*path' => "rails/mailers#preview", internal: true
52-
end
53-
end
54-
5548
ActionDispatch::IntegrationTest.send :include, ActionMailer::TestCase::ClearTestDeliveries
5649
end
5750
end
@@ -62,9 +55,18 @@ class Railtie < Rails::Railtie # :nodoc:
6255
end
6356
end
6457

65-
config.after_initialize do
66-
if ActionMailer::Base.preview_path
67-
ActiveSupport::Dependencies.autoload_paths << ActionMailer::Base.preview_path
58+
config.after_initialize do |app|
59+
options = app.config.action_mailer
60+
61+
if options.show_previews
62+
app.routes.prepend do
63+
get '/rails/mailers' => "rails/mailers#index", internal: true
64+
get '/rails/mailers/*path' => "rails/mailers#preview", internal: true
65+
end
66+
67+
if options.preview_path
68+
ActiveSupport::Dependencies.autoload_paths << options.preview_path
69+
end
6870
end
6971
end
7072
end

0 commit comments

Comments
 (0)