Skip to content

Commit

Permalink
Set action_mailer.default_url_options values in development and `…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
stevepolitodesign committed Feb 26, 2024
1 parent 4730000 commit fa72229
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions 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.
Expand Down
Expand Up @@ -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.
Expand Down
Expand Up @@ -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
Expand Down

0 comments on commit fa72229

Please sign in to comment.