【发布时间】:2014-03-19 15:42:59
【问题描述】:
当我们运行 cron 作业时,我们在 Rails 应用程序中遇到了一个奇怪的问题。我们的 cron 作业运行成功,但之后会导致“缺少模板”错误。除非我们解决这个问题,否则测试团队不会允许通过,所以请帮助!
提供代码sn-p和flow。
/etc/crontab
55 5 * * * user sh /root_path/config/cron/shell_commands/environment/test.sh
test.sh
wget http://localhost:3000/cron_jobs/execute_cron_tasks/test/key
cron_jobs/execute_cron_tasks.rb
class CronJobs::ExecuteCronTasksController < ApplicationController
def test
CronTasks.test_cron if params[:key] && params[:key] == "key"
respond_to do |format|
format.html {render :status => Rack::Utils.status_code(:ok)}
format.js {render :status => Rack::Utils.status_code(:ok)}
end
end
end
模块 cron_tasks.rb
module CronTasks
def self.test_cron
puts "=======================working===========================".red
end
end
调用 cron 作业后,它会打印数据但抛出 500 Internal Server Error
服务器日志
Started GET "/cron_jobs/execute_cron_tasks/test/getmeinfirst" for 127.0.0.1 at 2014-02-19 15:27:13 +0530
Processing by CronJobs::ExecuteCronTasksController#test as */*
Parameters: {"key"=>"key"}
Completed 500 Internal Server Error in 30ms
ActionView::MissingTemplate (Missing template cron_jobs/execute_cron_tasks/test, application/test with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder]}. Searched in:
* "/root_path/app/views"
* "/root_path/.rvm/gems/ruby-2.0.0-p353/gems/devise-1.4.2/app/views"
):
app/controllers/cron_jobs/execute_cron_tasks_controller.rb:83:in `block (2 levels) in test'
app/controllers/cron_jobs/execute_cron_tasks_controller.rb:82:in `test'
Rendered /root_path/.rvm/gems/ruby-2.0.0-p353/gems/actionpack-3.2.13/lib/action_dispatch/middleware/templates/rescues/missing_template.erb within rescues/layout (0.3ms)
谢谢 问候
【问题讨论】:
标签: ruby-on-rails ruby cron