0

我正在使用 rails 控制台运行此代码,但我不断收到错误消息

NameError: 未初始化的常量 Subcategory::Subcategories

我一直试图让这段代码运行一段时间,但我所做的一切都不起作用。这是我在 Subcategories_controller.rb 中使用的代码

    def self.remove_subcat_when_expired
        Time.now == '21:00:00' ?

        nine_pm = Time.local(Date.today.year, Date.today.month, Date.today.day, 21, 0, 0)

        Subcategories.where("end_data <= #{nine_pm}").each do |subcategory|
        if (subcategory.end_date.today? and Time.now >= nine_pm) or subcategory.end_date < Date.Today
            subcategory.destroy
        end
    end

在我正在使用的 rails 控制台中运行

 Subcategory.remove_subcat_when_expired

行 Subcategories.where("... 导致问题,我需要初始化 'Subcategories' 但我不知道如何,非常感谢任何帮助。

4

0 回答 0