[英]How to run a rake task by command line in rails
I have defined a rake task as follows in a file called file_locker_task.rake
我在一个名为
file_locker_task.rake
的文件中定义了一个rake任务,如下所示
namespace :myspace do
task :process => :environment do
FileLocker.lock_files
end
end
How do I execute this rake task from the command line? 如何从命令行执行此rake任务? I tried:
我试过了:
rake myspace:process
and rake process
but both are throwing an error like this: rake myspace:process
和rake process
但两者都抛出这样的错误:
rake aborted!
Don't know how to build task 'process'
rake -T -A
from your Rails home directory to see all the tasks that rake knows about. rake -T -A
以查看rake知道的所有任务。 Yours must be in that list for rake to run it. lib/tasks
directory and its subdirectories for your .rake
files. lib/tasks
目录及其.rake
文件的子目录中.rake
。 Check that. Any ruby file (including other rakefiles) can be included with a standard Ruby
require
command.任何ruby文件(包括其他rakefiles)都可以包含在标准的Ruby
require
命令中。
- -
Additional rake files (with the file extension “.rake”) may be placed in rakelib directory located at the top level of a project (ie the same directory that contains the main Rakefile).
其他rake文件(文件扩展名为“.rake”)可以放在位于项目顶层的rakelib目录中(即包含主Rakefile的同一目录)。 Also, rails projects may include additional rake files in the lib/tasks directory.
此外,rails项目可能包含lib / tasks目录中的其他rake文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.