action_mailer.default_url_options not working for staging environment
When I am deploying to Hetzner using Capistrano deployment with
ActionView::Template::Error
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.
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 staging:
config/initializers/mail.rb seems to set
default_url_options[:host] as well:So I changed it to following:
Rails.application.reloader.to_prepare do
ActionMailer::Base.default_options = {from: Jumpstart.config.default_from_email}
if Rails.env.production?
ActionMailer::Base.default_url_options[:host] = Jumpstart.config.domain
ActionMailer::Base.smtp_settings.merge!(Jumpstart::Mailer.new(Jumpstart.config).settings)
end
if Rails.env.staging?
ActionMailer::Base.default_url_options[:host] = Rails.application.config.action_mailer.default_url_options[:host]
ActionMailer::Base.smtp_settings.merge!(Jumpstart::Mailer.new(Jumpstart.config).settings)
end
endFor staging:
I have manually edited config/environments/staging.rb to add this.
config.action_mailer.default_url_options = {host: "mydomain.com"}When I am going to server rails console and typing following:
I am getting the expected domain evaluated however I am still getting 500 errors for password reset request.
Please help.
ActionMailer::Base.default_url_options[:host]I am getting the expected domain evaluated however I am still getting 500 errors for password reset request.
Please help.
Notifications
You’re not receiving notifications from this thread.