Hello I'm writing a deploy script(rake task) for my mini project. And I have this part when I invoke the db seed :
Rake::Task['db:seed'].invoke
And also compiling assets :
Rake::Task['assets:precompile'].invoke
So I was wondering is there a way to invoke these tasks in production environment like you would do from a console like this :
RAILS_ENV=production rake db:seed
In Rails, you can do as :
[arup@app (master)]$ rails g task my_namespace my_task1
create lib/tasks/my_namespace.rake
[arup@app (master)]$ cat lib/tasks/my_namespace.rake
namespace :my_namespace do
desc "TODO"
task my_task1: :environment do
end
end
[arup@app (master)]$
Now see the Rakefile is ready for you.
Just open the Rakefile
you just created, and define your tasks.
namespace :my_namespace do
task my_task1: :environment do
Rake::Task['db:seed'].invoke
Rake::Task['assets:precompile'].invoke
end
end
Hints is 2.10 Custom Rake Tasks .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.