From 94a77b5f2b9eb4f57b535b2b0f9e8092e873971b Mon Sep 17 00:00:00 2001 From: Matt Brictson Date: Sat, 7 Sep 2024 15:18:32 -0700 Subject: [PATCH] Remove Action Mailer config fix; no longer needed in Rails 7.2+ (#104) Prior to Rails 7.2, the default Action Mailer config lacked values for `default_url_options`, which led to various problems. Nextgen has historically applied its own config to work around this issue. However, starting with Rails 7.2, this has been fixed, so our workaround is no longer needed. --- lib/nextgen/generators/action_mailer.rb | 19 ------------------- lib/nextgen/generators/rack_canonical_host.rb | 4 ++++ 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/lib/nextgen/generators/action_mailer.rb b/lib/nextgen/generators/action_mailer.rb index 7e9e325..37491d4 100644 --- a/lib/nextgen/generators/action_mailer.rb +++ b/lib/nextgen/generators/action_mailer.rb @@ -7,22 +7,3 @@ elsif rspec? empty_directory_with_keep_file "spec/mailers" end - -say_git "Ensure absolute URLs can be used in all environments" -insert_into_file "config/environments/development.rb", <<-RUBY, after: "raise_delivery_errors = false\n" - config.action_mailer.default_url_options = {host: "localhost:3000"} - config.action_mailer.asset_host = "http://localhost:3000" -RUBY - -insert_into_file "config/environments/test.rb", <<-RUBY, after: "config.action_mailer.delivery_method = :test\n" - config.action_mailer.default_url_options = {host: "localhost:3000"} - config.action_mailer.asset_host = "http://localhost:3000" -RUBY - -insert_into_file "config/environments/production.rb", <<-RUBY, after: /config\.action_mailer\.raise_deliv.*\n/ - config.action_mailer.default_url_options = { - host: ENV.fetch("RAILS_HOSTNAME", "app.example.com"), - protocol: "https" - } - config.action_mailer.asset_host = "https://\#{ENV.fetch("RAILS_HOSTNAME", "app.example.com")}" -RUBY diff --git a/lib/nextgen/generators/rack_canonical_host.rb b/lib/nextgen/generators/rack_canonical_host.rb index be9b887..d899b4b 100644 --- a/lib/nextgen/generators/rack_canonical_host.rb +++ b/lib/nextgen/generators/rack_canonical_host.rb @@ -8,3 +8,7 @@ insert_into_file "config.ru", %(use Rack::CanonicalHost, ENV.fetch("RAILS_HOSTNAME", nil) if ENV["RAILS_HOSTNAME"].present?\n), before: /^run Rails.application/ + +gsub_file "config/environments/production.rb", + /\bhost: "example\.com"/, + 'host: ENV.fetch("RAILS_HOSTNAME", "example.com")'