Skip to content

Commit 9412008

Browse files
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
1 parent 4730000 commit 9412008

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

railties/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
* Set `action_mailer.default_url_options` values in `development` and `test`.
2+
3+
Prior to this commit, new Rails applications would raise `ActionView::Template::Error`
4+
if a mailer included a url built with a `*_path` helper.
5+
6+
*Steve Polito*
7+
18
* Introduce `Rails::Generators::Testing::Assertions#assert_initializer`
29

310
Compliments the existing `initializer` generator action.

railties/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ Rails.application.configure do
4343
config.action_mailer.raise_delivery_errors = false
4444

4545
config.action_mailer.perform_caching = false
46+
47+
config.action_mailer.define_url_options = { host: "localhost", port: 3000 }
4648
<%- end -%>
4749

4850
# Print deprecation notices to the Rails logger.

railties/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ Rails.application.configure do
4444
# ActionMailer::Base.deliveries array.
4545
config.action_mailer.delivery_method = :test
4646

47+
# Unlike controllers, the mailer instance doesn't have any context about the
48+
# incoming request so you'll need to provide the :host parameter yourself.
49+
config.action_mailer.default_url_options = { host: "www.example.com" }
50+
4751
<%- end -%>
4852
# Print deprecation notices to the stderr.
4953
config.active_support.deprecation = :stderr

0 commit comments

Comments
 (0)