开始:这是我第一次尝试从模型/控制器空间中获取业务逻辑。这是我试图抽象的一些初始逻辑。路径是app/services/Date_calc.rb
。
class Date_calc
require User
require Report
def months(range)
User.first.reports.order("report_month desc").limit(range).pluck(:report_month)
end
end
在我的应用程序中,我有两个模型,用户和报告。用户 has_many 报告。该reports
表有一个名为 的字段report_month
。
Date_calc.months(6)
在 Rails 控制台中调用返回: TypeError: no implicit conversion of Class into String
.
我的预期响应是一系列日期,例如["01/01/2013", "01/02/2013", "01/03/2013", ... ]
.
我不确定我在这里做错了什么。