2015-09-04 33 views
8

我在Rails 3.2应用程序中使用gem'clockwork'。该应用程序在Heroku上运行。时钟作业在凌晨1点运行 - 但它不执行代码。Rails发条不运行代码

这里是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 

回答

7

的错误是在该路线不存在。由于路由存在,这个问题通常意味着Rails路由尚未加载到当前作用域中。

您可能需要包括为了Rails的路线助手才能正常发挥作用:或者Rails.application.routes.url_helpers

Clockwork.every(1.day, 'DailyJob', :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 

# ...