From 941200814d6825bd00bd8fe827102b7c854317e6 Mon Sep 17 00:00:00 2001 From: Steve Polito Date: Mon, 26 Feb 2024 05:20:59 -0500 Subject: [PATCH 1/2] 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..72794554920b9 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 From fc44197a0e0f7cf88d5e7209dc6e85780d9e9cfa Mon Sep 17 00:00:00 2001 From: Steve Polito Date: Tue, 27 Feb 2024 05:39:51 -0500 Subject: [PATCH 2/2] Update railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Rafael Mendonça França --- .../rails/app/templates/config/environments/development.rb.tt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 ec92835ad14aa..4610e99c7fc69 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 @@ -44,7 +44,7 @@ Rails.application.configure do config.action_mailer.perform_caching = false - config.action_mailer.define_url_options = { host: "localhost", port: 3000 } + config.action_mailer.default_url_options = { host: "localhost", port: 3000 } <%- end -%> # Print deprecation notices to the Rails logger.