【问题标题】:Sidekiq with a tabless ModelSidekiq 与 tables 模型
【发布时间】:2013-06-12 18:50:33
【问题描述】:

我有一个使用 MailForm (plataformatec) 的联系人页面的无表格模型。我想使用 Sidekiq 将邮件发送移动到后台进程,但它依赖于给定模型的 id。

有谁知道如何将这封电子邮件发送到后台进程?

这是我的模特

class Contact < MailForm::Base 

  attribute :name,      :validate => true, :message => "aaa"
  attribute :email,     :validate => /\A([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})\z/i
  attribute :phone,     :validate => true
  attribute :nickname,  :captcha  => true

  def headers
    {
      :subject => "#{name}",
      :to => "test@test.com",
      :from => %("#{name}" <#{email}>)
    }
  end
end

【问题讨论】:

    标签: ruby-on-rails ruby model sidekiq


    【解决方案1】:

    好吧,如果你不坚持它,你需要将所有数据传递给 Sidekiq。例如,您可以将其作为哈希传递。

    class ContactMailFormWorker
      include Sidekiq::Worker
    
      def perform(attributes)
        contact = Contact.new attributes
        contact.deliver
      end
    end
    

    在您的控制器、模型或其他任何东西中

    ContactMailFormWorker.perform_async contact.attributes
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-24
      • 1970-01-01
      • 2013-02-06
      • 2020-07-25
      • 2014-06-26
      • 2014-04-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多