How do I change forgot password reset url in a multitenant app with multiple domains?
What I ended up doing was overriding
Devise::Mailer and setting the account instance variable for each Devise mailer there.class DeviseMailer < Devise::Mailer
layout "customer_mailer"
def confirmation_instructions(record, token, opts={})
@account = Current.account
if @account.domain.present?
@confirmation_link = "https://#{@account.domain}/users/confirmation?confirmation_token=#{token}"
else
if Rails.env.development?
@confirmation_link = "http://#{@account.subdomain}.lvh.me:3000/users/confirmation?confirmation_token=#{token}"
else
@confirmation_link = "https://#{@account.subdomain}.example.com/users/confirmation?confirmation_token=#{token}"
end
end
opts[:from] = "you.can.override.from@here.com"
opts[:reply_to] = "you.can.override.reply_to@here.com"
opts[:subject] = "You can override subject here."
super
end
endAnd then in the mailer views themselves, simply use the instance vars.
confirmation_instructions.html.erb
<h1><%= @account.name %></h1>
<p><%= t('.greeting', recipient: @email) %></p>
<p><%= t('.instruction') %></p>
<p><a href="<%= @confirmation_link %>">Confirm my account</a></p>A note about the registrations controller: You may experience a race condition if you try to send a mailer before the
account_user record is saved to the database. For that you might need to call:
resource.skip_confirmation_notification!And then after the
account_user record is saved you would need to manually trigger the confirmation email to send:current_user.send_confirmation_instructionsNotifications
You’re not receiving notifications from this thread.