2012-07-10 6 views
0

rake를 사용하여 Rails 2.3.2 응용 프로그램을 사용하여 작업을 실행하고 있습니다.call rake 시스템에서 지정한 파일을 찾을 수 없습니다.

이 내 코드의 일부입니다

application_controller.rb 

def call_rake(task, options = {}) 
    options[:rails_env] ||= Rails.env 
    args = options.map { |n, v| "#{n.to_s.upcase}='#{v}'" } 
    system "/usr/bin/rake #{task} #{args.join(' ')} start" 
    end 

라인 실행 :

system "/usr/bin/rake #{task} #{args.join(' ')} start" 

가 작업을 실행하지 않는 말 : 난

The system cannot find the file specified. 

Windows에서 이것을 실행하고 이미 시작하려면 &을 변경해야했습니다.이 Windows가 관련되어 있습니까? 아니면 뭔가 빠졌습니까?

일부 다른 코드 :

forbidden_file.rake 

desc "Process CSV file" 
task :process_file => :environment do 
    forbidden_file = ForbiddenFile.find(ENV["csv"]) 
    forbidden_file.upload_file 
end 

컨트롤러

... 
call_rake :process_file, :csv => params[:files] 
redirect_to forbidden_files_url 
... 

답변

1

예는 윈도우 윈도우 레이크 위치에 관련되어 c:\ruby\ruby192\bin\rake 같은 것입니다. 플랫폼 독립적 인 경우 절대 경로를 사용하여 명령을 호출하지 마십시오. 컨트롤러 사용으로 인한

실행하려면 작업 :

%x[rake name_task] 

또는 다른 방법 :

require 'rake' 

Rake::Task.clear #clears tasks loaded in dev mode 
YourApplicationName::Application.load_tasks # put your application name 

class RakeController < ApplicationController 

    def call_rake(task, options = {}) 
    Rake::Task[task].reenable # if you going to invoke the same task second time. 
    Rake::Task[task].invoke(options) 
    end 

end 
관련 문제