1

我在 Rails Admin 中有一个自定义收集操作,如下所示:

需要'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

我不明白是什么原因造成的

任何帮助表示赞赏。

4

0 回答 0