I was following the Action Mailer guideon https://guides.rubyonrails.org/action_mailer_basics.html#calling-the-mailer
I did almost the same of what tutorial show. The controller:
def create
@user = User.create(user_params)
if @user && UserMailer.with(user: @user).welcome_email.deliver_later
token = encode_token({ user_id: @user.id })
render json: { token: token }, status: :created
else
render json: @user.errors.messages, status: :bad_request
end
end
The Mailer:
class UserMailer < ApplicationMailer
default from: 'notifications@example.com'
def welcome_email
@user = params[:user]
@url = 'http://example.com/login'
mail(to: @user.email, subject: 'Welcome to My Awesome Site')
end
end
But when I make the request Active Job yells:
ActiveJob::SerializationError => "Unsupported argument type: User"
It works correctly using deliver_now
This shows that we have a problem with :async
adapter. But as the guide says:
Active Job's default behavior is to execute jobs via the :async adapter. So, you can use deliver_later to send emails asynchronously. Active Job's default adapter runs jobs with an in-process thread pool. It's well-suited for the development/test environments, since it doesn't require any external infrastructure, but it's a poor fit for production since it drops pending jobs on restart. If you need a persistent backend, you will need to use an Active Job adapter that has a persistent backend (Sidekiq, Resque, etc).
So what I'm missing here?