我应该把模型放在哪里以便随时可以访问它们?

Where do I put model so that whenever could access them?

简单但可能很愚蠢的问题。就在哪儿? /models 中的简单生成模型不起作用,/lib 中的新 class 也不起作用...只是关于未定义方法等的错误

schedule.rb

every '* * * * *' do
runner 'UpdateDaysAgo.test'
end

型号

class UpdateDaysAgo < ActiveRecord::Base
  def test
    UpdateDaysAgo.create(channel: "nil", title: "nil", game: "nil", avatar: "nil", created_at: Time.now, updated_at: Time.now)
  end
end

错误

/usr/local/rvm/gems/ruby-2.2.1/gems/activerecord-4.2.1/lib/active_record/dynamic_matchers.rb:26:in `method_missing': private method `test' called for #<Class:0x00000004db7b40> (NoMethodError)

只要工作正常,command 上的某些 cron 作业就很好。但是我不知道 modelsrunner :/

您应该创建 class method:

class UpdateDaysAgo < ActiveRecord::Base
  def self.test
    UpdateDaysAgo.create(channel: "nil", title: "nil", game: "nil", avatar: "nil", created_at: Time.now, updated_at: Time.now)
  end
end