From fa7222984dbbcb0a45ded7dae07c06713a32ab0c Mon Sep 17 00:00:00 2001 From: Steve Polito Date: Mon, 26 Feb 2024 05:20:59 -0500 Subject: [PATCH] Set `action_mailer.default_url_options` values in `development` and `test`. Prior to this commit, new Rails applications would raise `ActionView::Template::Error` if a mailer included a url built with a `*_path` helper. Since we already know [new apps will be served on `localhost:3000`][new apps], we set this as the value in `development`. In an effort to remain consistent with existing patters, we set the `host` to `www.example.com` in `test. [new apps]: https://github.com/rails/rails/blob/47300002db11d67d7b35103f5c429dad7dacdacd/README.md?plain=1#L81 --- railties/CHANGELOG.md | 7 +++++++ .../app/templates/config/environments/development.rb.tt | 2 ++ .../rails/app/templates/config/environments/test.rb.tt | 4 ++++ 3 files changed, 13 insertions(+) diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 454c4361d843e..8cf48977fff8e 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,3 +1,10 @@ +* Set `action_mailer.default_url_options` values in `development` and `test`. + + Prior to this commit, new Rails applications would raise `ActionView::Template::Error` + if a mailer included a url built with a `*_path` helper. + + *Steve Polito* + * Introduce `Rails::Generators::Testing::Assertions#assert_initializer` Compliments the existing `initializer` generator action. diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt index 9d9f0d9ceb661..ec92835ad14aa 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt @@ -43,6 +43,8 @@ Rails.application.configure do config.action_mailer.raise_delivery_errors = false config.action_mailer.perform_caching = false + + config.action_mailer.define_url_options = { host: "localhost", port: 3000 } <%- end -%> # Print deprecation notices to the Rails logger. diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt index 3fed28b706582..0ab0765dce5a9 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt @@ -44,6 +44,10 @@ Rails.application.configure do # ActionMailer::Base.deliveries array. config.action_mailer.delivery_method = :test + # Unlike controllers, the mailer instance doesn't have any context about the + # incoming request so you'll need to provide the :host parameter yourself. + config.action_mailer.default_url_options = { host: "www.example.com" } + <%- end -%> # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr