运行Cron Jobs时缺少模板

时间:2014-02-19 10:52:07

标签: ruby-on-rails ruby cron

当我们运行cron作业时,我们在 Rails 应用程序中遇到了一个奇怪的问题。我们的cron作业正在成功运行,但在此之后它会导致"缺少模板"错误。除非我们对此进行排序,否则测试团队将不允许通过它,所以请帮助!!

提供代码段和流程。

/ 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

module cron_tasks.rb

module CronTasks
  def self.test_cron
    puts "=======================working===========================".red
  end
end

调用cron作业后,它将打印数据但抛出500内部服务器错误

服务器日志

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)

由于 此致

1 个答案:

答案 0 :(得分:0)

我假设你不想在体内渲染任何东西。在这种情况下,请尝试

format.html {render :status => Rack::Utils.status_code(:ok), :nothing => true}

如果你想渲染一个视图,你可能应该把它放在:

app/views/cron_jobs/execute_cron_tasks/test.html.erb