次のように、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
何が原因かわかりません
どんな助けでも感謝します。