M.Octavio
M.Octavio

Reputation: 1808

call rake The system cannot find the file specified

I'm working with a Rails 2.3.2 application using rake to run a task.

This is part of my code:

 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

When running the line:

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

it doesn't run the task and say:

The system cannot find the file specified.

I'm running this on Windows and already had to change & for start, is this Windows related or I'm missing something?

Some other code:

forbidden_file.rake

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

Controller

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

Upvotes: 0

Views: 885

Answers (1)

rogal111
rogal111

Reputation: 5933

Yes is windows related, in Windows rake location is something like c:\ruby\ruby192\bin\rake. Do not use absolute paths to invoke commands if you want to be platform independent.

To run tasks from controller use:

%x[rake name_task]

or another way:

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

Upvotes: 1

Related Questions