We've moved discussions to Discord

action_mailer.default_url_options not defined in staging?

When deployed on Heroku with RAILS_ENV=staging, the "Forgot password" page (/users/password/new) returns an error 500:

ActionView::Template::Error
Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true

from app/views/devise/mailer/reset_password_instructions.html.erb at line 5:

<p><%= link_to t('.action'), edit_password_url(@resource, reset_password_token: @token) %></p>

---

This works fine in development and in production however, so it seems closely related to the staging environment.

For development:
action_mailer.default_url_options[:host] is set in config/environments/development.rb:

config.action_mailer.default_url_options = {host: "lvh.me", port: ENV.fetch("PORT", 3000).to_i}

For production:
config/initializers/mail.rb seems to set default_url_options[:host] as well:

if Rails.env.production?
  ActionMailer::Base.default_url_options[:host] = Jumpstart.config.domain

For staging:
Should I manually edit config/environments/staging.rb to add this?
config.action_mailer.default_url_options = {host: "lvh.me", port: ENV.fetch("PORT", 3000).to_i}

Or should I edit config/initializers/mail.rb like this?
if Rails.env.production? || Rails.env.staging?

Thanks!
Chris Oliver
The mail.rb initializer only configures Production, you can add additional ones there.

We might update the config so you can set each environment separately.
Kips Davenport
As some of the docs reference setting up a staging env, setting the environment config individually would probably avoid this sort of confusion.
Notifications
You’re not receiving notifications from this thread.