diff options
author | Andrew White <andyw@pixeltrix.co.uk> | 2014-01-04 18:42:34 +0000 |
---|---|---|
committer | Andrew White <andyw@pixeltrix.co.uk> | 2014-01-04 18:42:34 +0000 |
commit | 3713e433667ee95caccb53a4062f540405272234 (patch) | |
tree | 42307a827be7815213d771eab0b6baf1efef6e34 /actionmailer | |
parent | 81066b115817a4c95c83a76553954317f737cd14 (diff) | |
download | rails-3713e433667ee95caccb53a4062f540405272234.tar.gz rails-3713e433667ee95caccb53a4062f540405272234.tar.bz2 rails-3713e433667ee95caccb53a4062f540405272234.zip |
Add preview_path to autoload_paths in after_initialize
Only config.autoload_paths is frozen, so add the preview_path
to ActiveSupport::Dependencies.autoload_paths directly in an
after_initialize block. Also protect against a blank preview_path
being added to autoload_paths which can cause a serious slowdown
as Dir[] tries to load all *_preview.rb files under /
Fixes #13372
Diffstat (limited to 'actionmailer')
-rw-r--r-- | actionmailer/lib/action_mailer/preview.rb | 8 | ||||
-rw-r--r-- | actionmailer/lib/action_mailer/railtie.rb | 12 |
2 files changed, 14 insertions, 6 deletions
diff --git a/actionmailer/lib/action_mailer/preview.rb b/actionmailer/lib/action_mailer/preview.rb index 43d9ec4bb5..ecceaf8c70 100644 --- a/actionmailer/lib/action_mailer/preview.rb +++ b/actionmailer/lib/action_mailer/preview.rb @@ -56,12 +56,18 @@ module ActionMailer protected def load_previews #:nodoc: - Dir["#{preview_path}/**/*_preview.rb"].each{ |file| require_dependency file } + if preview_path? + Dir["#{preview_path}/**/*_preview.rb"].each{ |file| require_dependency file } + end end def preview_path #:nodoc: Base.preview_path end + + def preview_path? #:nodoc: + Base.preview_path? + end end end end diff --git a/actionmailer/lib/action_mailer/railtie.rb b/actionmailer/lib/action_mailer/railtie.rb index af8009ba97..c893ddfef5 100644 --- a/actionmailer/lib/action_mailer/railtie.rb +++ b/actionmailer/lib/action_mailer/railtie.rb @@ -19,6 +19,10 @@ module ActionMailer options.javascripts_dir ||= paths["public/javascripts"].first options.stylesheets_dir ||= paths["public/stylesheets"].first + if Rails.env.development? + options.preview_path ||= defined?(Rails.root) ? "#{Rails.root}/test/mailers/previews" : nil + end + # make sure readers methods get compiled options.asset_host ||= app.config.asset_host options.relative_url_root ||= app.config.relative_url_root @@ -41,11 +45,9 @@ module ActionMailer end end - initializer "action_mailer.configure_mailer_previews", before: :set_autoload_paths do |app| - if Rails.env.development? - options = app.config.action_mailer - options.preview_path ||= defined?(Rails.root) ? "#{Rails.root}/test/mailers/previews" : nil - app.config.autoload_paths << options.preview_path + config.after_initialize do + if ActionMailer::Base.preview_path? + ActiveSupport::Dependencies.autoload_paths << ActionMailer::Base.preview_path end end end |