我使用mail_form gem并拥有以下代码
def create
@contact = Contact.new(contact_params)
@contact.request = request
respond_to do |format|
if @contact.deliver
format.html { redirect_to root_path, notice: "Thank you for your message."}
else
format.html {render :new, error: "There was a problem with sending your message."}
end
end
end
当我提交联系表单时,发送邮件并重定向到主页需要几秒钟。
如何使用sidekiq使此过程异步?
答案 0 :(得分:-1)
将Sidekiq设置为Active Job的后端 http://edgeguides.rubyonrails.org/active_job_basics.html
然后使用ActionMailer中的deliver_later方法
http://edgeapi.rubyonrails.org/classes/ActionMailer/MessageDelivery.html#method-i-deliver_later