我的目录中有一个邮件程序:
@SpringBootApplication
@ComponentScan(excludeFilters = @ComponentScan.Filter(
type = FilterType.CUSTOM, classes = { ExcludePackageTypeFilter.class }))
public class Application {
}
我在此邮件中的代码为:
/my_app/app/mailers
对于从该邮件发送出去的电子邮件,我需要附加一个从class MyMailer < ApplicationMailer
default from: 'todd@myemail.com'
include Reports::OrderReport
def welcome_email
email = params[:email]
mail(to: email, subject: 'Welcome to My Awesome Site')
sheet = OrderReport.new
sheet.create_workbook
end
end
中定义的类生成的excel报告,该类中的代码如下:
/my_app/app/reports
但是当我尝试使用此命令运行邮件时:
class OrderReport
require 'axlsx'
attr_reader :shop, :order_workbook
def initialize
workbook_instance = Axlsx::Package.new
@order_workbook = workbook_instance.workbook
end
def create_workbook
order_workbook.add_worksheet(:name => "Basic Worksheet") do |sheet|
sheet.add_row ["First Column", "Second", "Third"]
sheet.add_row [1, 2, 3]
sheet.add_row [' preserving whitespace']
end
order_workbook.serialize("test_book.xlsx")
end
end
我收到以下错误:
MyMailer.with(email: "this_email@gmail.com").welcome_email.deliver_now
我哪里出错了?
答案 0 :(得分:1)
您正在尝试添加class OrderReport
(Rails期望包含模块)
只需删除include Reports::OrderReport
就可以解决问题
另外,由于Rails文件的命名,您还应该在/my_app/app/reports/order_report.rb和您的邮件中将类重命名为Reports::OrderReport
答案 1 :(得分:0)
我认为您需要对使用类名称的方式进行一些更改。命名应一致。如果愿意,还可以将OrderReport类包装在报告模块中。
JSON