Skip to content

Commit

Permalink
Remove Action Mailer config fix; no longer needed in Rails 7.2+ (#104)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mattbrictson authored Sep 7, 2024
1 parent fb066d5 commit 94a77b5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 19 deletions.
19 changes: 0 additions & 19 deletions lib/nextgen/generators/action_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions lib/nextgen/generators/rack_canonical_host.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")'

0 comments on commit 94a77b5

Please sign in to comment.