I need to run a series of Rake tasks from another Rake task. The first three tasks need to be run in the development environment, but the final task needs to be run in the staging environment. The task has a dependency on :environment
which causes the Rails development environment to be loaded before the tasks run.
However, I need the final task to be executed in the staging environment.
Passing a RAILS_ENV=staging
flag before invoking the rake task is no good as the environment has already loaded at this point and all this will do is set the flag, not load the staging environment.
Is there a way I can force a rake task in a specific environment?
system({RAILS_ENV: 'staging'}, "rake staging_command")
. – Leonid Shevtsovsystem
, but it doesn't reload the environment. – Undistractionapplication.rb
which is not loaded a second time. – Undistraction