Rails mailer ignores attachment when using deliver_later with sidekiq

What works

My current code for user_controller.rb:

def create
  u = User.new(create_user_params)
  .
  .
  .
  if u.save
    WelcomeMailer.new_customer(u).deliver_now
    render json: u.as_json(except: [:password_digest]), status: 201
  else
    respond_with u
  end
end

My Mailer Code:

def new_customer(user:)
  @user = user
  attachments["AGB.pdf"] = File.read("#{Rails.root}/app/assets/files/AGB.pdf")
  mail to: @user.email, subject: "blaa blubb"
end

and his work is like a charm.

E-mail is sent with the application.

Problem:

If i change

WelcomeMailer.new_customer(u).deliver_now

to

WelcomeMailer.new_customer(u).deliver_later

I receive mail, but WITHOUT attachments.

I use sidekiq as a job queue (config / application.rb):

config.active_job.queue_adapter = :sidekiq
+4
source share
1 answer

Good...

noobish answer:

You need to restart the sidekiq queues ... Does this already work in a few weeks as a hittingmyself charm

+1
source

Source: https://habr.com/ru/post/1589154/


All Articles