Rails 如何运行 rake 任务
如何在终端/控制台中运行这个 rake 文件?
我的 statistik.rake 在 lib/tasks 中
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
How do I run this rake file in terminal/console?
my statistik.rake in lib/tasks
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
您尝试过
rake reklamer:iqmedier
吗?我的自定义 rake 任务位于 lib 目录中,而不是 lib/tasks 中。不确定这是否重要。
Have you tried
rake reklamer:iqmedier
?My custom rake tasks are in the lib directory, not in lib/tasks. Not sure if that matters.
如果您不确定如何运行 rake 任务,请首先找出您有哪些任务,它还会列出运行这些任务的命令。
在终端上运行 rake --tasks 。
它将列出如下任务:
然后您可以使用以下命令运行任务:
rake gobble:dev:prime
如所列。If you aren't sure how to run a rake task, first find out first what tasks you have and it will also list the commands to run the tasks.
Run
rake --tasks
on the terminal.It will list the tasks like the following:
You can then run your task with:
rake gobble:dev:prime
as listed.作为 https://stackoverflow.com/a/5641807/7262646 和 https://stackoverflow.com/a/49400110/7262646描述
你必须添加
在文件的顶部。
YourAppName
来自config/applicaion.rb
,它被定义为一个命名空间,如:然后你可以用它
来调用你的任务。
As the https://stackoverflow.com/a/5641807/7262646 and https://stackoverflow.com/a/49400110/7262646 described
you have to add
on the top of the file.
YourAppName
comes fromconfig/applicaion.rb
, which is defined as a namespace, such as:and then you can use
to invoke your task.
在 Rails 4.2 中,上述方法不起作用。
要运行该文件中的所有任务,请在
相同的文件并运行 rake all
In rails 4.2 the above methods didn't work.
To Run all the tasks in that file assign the following inside the
same file and run rake all
您可以通过运行以下命令从 shell 运行 Rake 任务:
从 Ruby 运行(例如,在 Rails 控制台或另一个 Rake 任务中):
要使用单个任务在同一命名空间中运行多个任务,请在命名空间中创建以下新任务:
You can run Rake tasks from your shell by running:
To run from from Ruby (e.g., in the Rails console or another Rake task):
To run multiple tasks in the same namespace with a single task, create the following new task in your namespace:
或者
or
有时您的 rake 任务不会加载到控制台中,在这种情况下您可以尝试以下命令
Sometimes Your rake tasks doesn't get loaded in console, In that case you can try the following commands