ruby-on-rails – Rails发条没有运行代码

我在Rails 3.2应用程序中使用gem’clockwork’.该应用程序正在Heroku上运行.时钟作业在凌晨1点运行 – 但它没有执行代码.

这是clock.rb代码

Clockwork.every(1.day,'DailyJob',:at => '01:00'){
    StatsMailer.stats_email.deliver
    Forecast.where(:run_date => Date.today).each  do |forecast|
      woschedules_run_jobplans_path(:id => forecast.woschedule_id)
    end
  }

日志显示

Sep 04 00:00:05 ndeavor-staging app/clock.1: #<NoMethodError: undefined method `woschedules_run_jobplans_path’ for Clockwork:Module>

如果我耙路线,我得到:

woschedules_run_jobplans GET   /woschedules/run_jobplans(.:format) woschedules#run_jobplans

解决方法

错误在于路线不存在.由于路径存在,这个问题通常意味着Rails路由尚未加载到当前范围.

您可能需要包含Rails的路由助手才能使其正常运行:Rails.application.routes.url_helpers

Clockwork.every(1.day,:at => '01:00'){
  StatsMailer.stats_email.deliver
  Forecast.where(:run_date => Date.today).each  do |forecast|
    # Prepend your route with the following:
    Rails.application.routes.url_helpers.woschedules_run_jobplans_path(:id => forecast.woschedule_id)
  end
}

或者,要稍微干一下,您可以使用以下命令在文件开头简单地包含所有路径助手:

# Beginning of file
include Rails.application.routes.url_helpers

# ...

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...