How do I run this rake file in terminal/console?
如何在终端/控制台运行这个rake文件?
my statistik.rake in lib/tasks
我的statistik。耙在lib /任务
desc "Importer statistikker"
namespace :reklamer do
task :iqmedier => :environment do
...
end
task :euroads => :environment do
...
end
task :mikkelsen => :environment do
...
end
task :orville => :environment do
...
end
end
6 个解决方案
#1
93
You shouldn't be running Rake tasks in the Rails console, but instead in the Terminal/Command Prompt by running
您不应该在Rails控制台中运行Rake任务,而应该在终端/命令提示符中运行
rake task_name
If you truly must run a Rake task in Ruby, you should be able to do:
如果您确实必须在Ruby中运行Rake任务,您应该能够做到:
Rake::Task['task_name'].invoke
but that's usually only done in a Rake task itself to run another.
但这通常只在Rake任务本身中完成,然后再运行另一个。
To run multiple tasks in the same namespace with a single task, create the following new task in your namespace:
要在同一个名称空间中运行多个任务,请在您的名称空间中创建以下新任务:
task :runall => [:iqmedier, :euroads, :mikkelsen, :orville ] do
# This will run after all those tasks have run
end
#2
20
Rake::Task['reklamer:orville'].invoke
or
或
Rake::Task['reklamer:orville'].invoke(args)
#3
18
Have you tried rake reklamer:iqmedier
?
你试过rake reklamer:iqmedier吗?
My custom rake tasks are in the lib directory, not in lib/tasks. Not sure if that matters.
我的自定义rake任务在lib目录中,而不是在lib/tasks中。不确定这是否重要。
#4
1
In rails 4.2 the above methods didn't work.
在rails 4.2中,上述方法不起作用。
- Go to the Terminal.
- 去码头。
- Change the directory to the location where your rake file is present.
- 将目录更改为提供rake文件的位置。
- run rake task_name.
- 运行rake task_name。
- In the above case, run rake iqmedier - will run only iqmedir task.
- 在上面的例子中,运行rake iqmedier -将只运行iqmedir任务。
- run rake euroads - will run only the euroads task.
- 运行rake euroads -将只运行euroads任务。
-
To Run all the tasks in that file assign the following inside the same file and run rake all
要运行该文件中的所有任务,请在同一文件中分配以下任务并运行rake all
task :all => [:iqmedier, :euroads, :mikkelsen, :orville ] do #This will print all the tasks o/p on the screen end
#5
0
here is a very good tutorial on running rake tasks that i found helpful..
这里有一个关于运行rake任务的很好的教程,我觉得很有用。
http://jasonseifer.com/2010/04/06/rake-tutorial
http://jasonseifer.com/2010/04/06/rake-tutorial
#6
0
Sometimes Your rake tasks doesn't get loaded in console, In that case you can try the following commands
有时您的rake任务不会在控制台中加载,在这种情况下,您可以尝试以下命令
require "rake"
YourApp::Application.load_tasks
Rake::Task['Namespace:task'].invoke
#1
93
You shouldn't be running Rake tasks in the Rails console, but instead in the Terminal/Command Prompt by running
您不应该在Rails控制台中运行Rake任务,而应该在终端/命令提示符中运行
rake task_name
If you truly must run a Rake task in Ruby, you should be able to do:
如果您确实必须在Ruby中运行Rake任务,您应该能够做到:
Rake::Task['task_name'].invoke
but that's usually only done in a Rake task itself to run another.
但这通常只在Rake任务本身中完成,然后再运行另一个。
To run multiple tasks in the same namespace with a single task, create the following new task in your namespace:
要在同一个名称空间中运行多个任务,请在您的名称空间中创建以下新任务:
task :runall => [:iqmedier, :euroads, :mikkelsen, :orville ] do
# This will run after all those tasks have run
end
#2
20
Rake::Task['reklamer:orville'].invoke
or
或
Rake::Task['reklamer:orville'].invoke(args)
#3
18
Have you tried rake reklamer:iqmedier
?
你试过rake reklamer:iqmedier吗?
My custom rake tasks are in the lib directory, not in lib/tasks. Not sure if that matters.
我的自定义rake任务在lib目录中,而不是在lib/tasks中。不确定这是否重要。
#4
1
In rails 4.2 the above methods didn't work.
在rails 4.2中,上述方法不起作用。
- Go to the Terminal.
- 去码头。
- Change the directory to the location where your rake file is present.
- 将目录更改为提供rake文件的位置。
- run rake task_name.
- 运行rake task_name。
- In the above case, run rake iqmedier - will run only iqmedir task.
- 在上面的例子中,运行rake iqmedier -将只运行iqmedir任务。
- run rake euroads - will run only the euroads task.
- 运行rake euroads -将只运行euroads任务。
-
To Run all the tasks in that file assign the following inside the same file and run rake all
要运行该文件中的所有任务,请在同一文件中分配以下任务并运行rake all
task :all => [:iqmedier, :euroads, :mikkelsen, :orville ] do #This will print all the tasks o/p on the screen end
#5
0
here is a very good tutorial on running rake tasks that i found helpful..
这里有一个关于运行rake任务的很好的教程,我觉得很有用。
http://jasonseifer.com/2010/04/06/rake-tutorial
http://jasonseifer.com/2010/04/06/rake-tutorial
#6
0
Sometimes Your rake tasks doesn't get loaded in console, In that case you can try the following commands
有时您的rake任务不会在控制台中加载,在这种情况下,您可以尝试以下命令
require "rake"
YourApp::Application.load_tasks
Rake::Task['Namespace:task'].invoke