嗨,对 Rails 很陌生,目前正在处理 rake 文件中的任务定义。这是我的代码
test_task.rake
namespace :test_name_space do
namespace :to do
task :my_task do
p "========================="
sample_out_put = SOutput.new
sample_out_put.createfileoutput
end
end
end
在我的 SOutput
class SOutput
def createfileoutput
current_time = Time.new
puts "====================================="
puts "This is a scheduled file output"
puts "====================================="
File.open("/home/kalanamith/Desktop/out.txt", "a+") do |file|
p current_time.inspect.to_s
file.write("This is a sample test")
file.write(current_time.inspect.to_s)
end
end
fileoutput = SOutput.new
fileoutput.createfileoutput
end
当我运行
rake test_name_space:to:my_task
"========================="
rake aborted!
uninitialized constant SOutput
嗯,上面的错误我没有关于这个错误的大图景。谁能指导我?
/home/kalanamith/Documents/rails_rnd/rails_cron/lib/tasks/test_task.rake:6:in `block (3 levels) in <top (required)>'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:246:in `call'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:246:in `block in execute'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:241:in `each'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:241:in `execute'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:184:in `block in invoke_with_call_chain'
/usr/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:177:in `invoke_with_call_chain'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:170:in `invoke'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:143:in `invoke_task'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:101:in `block (2 levels) in top_level'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:101:in `each'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:101:in `block in top_level'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:110:in `run_with_threads'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:95:in `top_level'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:73:in `block in run'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:160:in `standard_exception_handling'
/var/lib/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:70:in `run'
/var/lib/gems/1.9.1/gems/rake-10.0.4/bin/rake:33:in `<top (required)>'
/usr/local/bin/rake:19:in `load'
/usr/local/bin/rake:19:in `<main>'
Tasks: TOP => test_name_space:to:my_task