在Rails_admin内发送延迟作业的电子邮件会导致错误

时间:2013-02-12 11:19:49

标签: ruby-on-rails-3.2 delayed-job rails-admin

我在Rails管理员中有一个自定义集合操作,如下所示:

需要'rails_admin / config / actions' 需要'rails_admin / config / actions / base'

module RailsAdminSendNewsletter
end

module RailsAdmin
  module Config
    module Actions
      class SendNewsletter < RailsAdmin::Config::Actions::Base

      # Is the action on a model scope (Example: /admin/team/export)
       register_instance_option :collection? do
         true
       end

       register_instance_option :link_icon do
          'icon-share'
       end

       register_instance_option :pjax? do
           false
         end

        register_instance_option :controller do
          Proc.new do
              if request.xhr?
                  resources = Resource.where(:for_newsletter => true)
                  subscriber = Subscriber.all.each do |subscriber|
                     NewsletterMailer.delay.newsletter(subscriber, resources)
                  end
                  resources.each do |resource|
                        resource.update_column(:sent_on, Time.now)
                      end   
              end
                flash[:success] = "The Newsletter has successfully been sent."
                redirect_to back_or_index
          end  
      end


      end
    end
  end
end

产生以下错误:

ArgumentError (wrong number of arguments (2 for 1)):
  lib/rails_admin_send_newsletter.rb:30:in `block (3 levels) in <class:SendNewsletter>'
  lib/rails_admin_send_newsletter.rb:29:in `each'
  lib/rails_admin_send_newsletter.rb:29:in `block (2 levels) in <class:SendNewsletter>'

以下是时事通讯邮件:

class NewsletterMailer < ActionMailer::Base
    default from: ' "Agile Designers" <info@agiledesigner.com>'


    def newsletter(subscriber, resources)
        @subscriber = subscriber
        @resources = resources
        @twitter = "https://twitter.com/agiledesigners"
        mail(:to => subscriber.email, :subject => "Agile Designer Newsletter")
    end
end

我不明白是什么导致它

任何帮助表示感谢。

0 个答案:

没有答案