In my Rails 5 app I am trying to send emails with ActiveJob and Sucker Punch:
# app/controllers/users_controller.rb
class UsersController < ApplicationController
def activate
user = User.find_by(:activation_token => params[:id])
user.activate
SendFollowUpEmailJob.perform_in(30, user)
sign_in user
end
end
# app/jobs/send_follow_up_email.rb
class SendFollowUpEmailJob < ActiveJob::Base
include SuckerPunch::Job
queue_as :default
def perform(user)
SupportMailer.follow_up(user).deliver_later
end
end
# app/mailers/support_mailer.rb
class SupportMailer < ApplicationMailer
layout nil
default :from => "admin@app.com"
def follow_up(user)
@user = user
mail :to => @user.email, :subject => t('.subject')
end
end
# app/views/user_mailer/activation.html.erb
<%= link_to(t('views.activate'), activate_user_url(@user.activation_token, :locale => "#{I18n.locale}")) %>
Everything works except that the email is always sent in the default locale rather than the locale that was passed into the activate
action.
All emails throughout the application are always sent in the correct locale, so it must down to either ActiveJob or SuckerPunch.
If you can help, please let me know. Thanks.