Force Rake Task To Run in Specific Rails Environment

I’ve accomplished this kind of this before, albeit not in the most elegant of ways:

task :prepare do
  system("bundle exec rake ... RAILS_ENV=development")      
  system("bundle exec rake ... RAILS_ENV=development")
  system("bundle exec rake ... RAILS_ENV=test")
  system("bundle exec rake ... RAILS_ENV=test")
  system("bundle exec rake ... RAILS_ENV=test")
  system("bundle exec rake ... RAILS_ENV=test")
end

It’s always worked for me. I’d be curious to know if there was a better way.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)