2014-02-19 99 views
1

在我們運行cron作業時,我們在Rails應用程序中遇到了一個奇怪的問題。我們的cron作業正在成功運行,但之後會導致「Missing Template」錯誤。除非我們解決這個問題,否則測試團隊將不會允許這樣做,所以請幫助!運行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 

模塊cron_tasks.rb

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

調用cron作業,將打印數據,但拋出500內部服務器錯誤

Server日誌

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) 

感謝 問候

回答

0

我假設你不想渲染任何東西。在這種情況下,嘗試

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

如果你想呈現一個視圖,你probabily應該把它放在:

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

您好,感謝重播。現在工作正常,但是有一個小問題。它正在創建一個名爲「key」的文件,我將這個文件傳遞給根文件夾中的請求。你能告訴一下問題是什麼。 – apr