加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 19:08:21 所属栏目:百科 来源:网络整理
导读:我在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
我在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

# ...

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读