无法进行可创意的Resque作业-#<user:0x

时间:2019-05-08 06:58:10

标签: ruby-on-rails devise resque devise-invitable apartment-gem

=“”

Ruby on Rails Project,我正在运行Resque,未定义方法`invitation_instructions'处理电子邮件(特别是Devise和Devise Invitable)。 Devise电子邮件发送正常(通过API通过邮戳gem发送出去),但是devise_invitable电子邮件在undefined method invitation_instructions for #User:0x0xxxxxx Did you mean? invitations_count的Resque中失败。

通过默认的devmail发送时,一切正常,但是使用我的自定义邮件失败。我想添加一个内联附件,因此需要自定义邮件。

自定义设计邮件程序:

class DeviseMailer < Devise::Mailer
    helper  :application

    include Devise::Controllers::UrlHelpers
    include Devise::Mailers::Helpers
    include DeviseInvitable::Mailer

    default template_path: 'devise/mailer'
    default from: sender@example.com
    layout  'mailer_devise'

    before_action :add_inline_attachment!

    def reset_password_instructions(record, token, opts={})
        super
    end

    def invitation_instructions(record, token, opts={})
        @token = token
        devise_mail(record)#, record.invitation_instructions || :invitation_instructions, opts)
      end

    private

    def add_inline_attachment!
        attachments.inline['logo.png'] = File.read(Rails.root.join('app/assets/images/logo.png'))
    end
end

摘要:

def reset_password_instructions-工作正常

def invitation_instructions-失败,出现未定义的方法错误

1 个答案:

答案 0 :(得分:0)

由于其他原因,我最终迁移到了Sidekiq。下面是我更新的Devise Mailer类,它运行良好。无需定义invitation_instructions方法,因为before_action回调函数附加了内嵌图像,这就是我一开始的想法。

class DeviseMailer < Devise::Mailer
  helper  :application
  include Devise::Controllers::UrlHelpers
  include Devise::Mailers::Helpers
  include DeviseInvitable::Mailer

  default template_path: 'devise/mailer'
  default from: ENV['EMAIL_NAME']
  layout  'mailer_devise'

  before_action :add_inline_attachment!

  private

  def add_inline_attachment!
    attachments.inline['logo.png'] = File.read(Rails.root.join('app/assets/images/logo.png'))
  end
end