简体   繁体   中英

Setting rails environment with Foreman

How do you set the rails environment with Foreman?

For example, if I wanted to run bundle exec rake assets:precompile on my development machine, but I wanted to set the rails environment to production so I could see exactly how this process would run on the production server - I could do this using vanilla rails by doing RAILS_ENV=production bundle exec rake assets:precompile .

But how do I do this with Foreman? For example, I know I can do bundle exec foreman run rake assets:precompile , but that doesn't specify the rails environment as production.

The solution is to use a .env file in your project's root directory . Inside that file, add this line:

RAILS_ENV=production

Now, anytime you run Foreman locally, it will set the rails environment to production. So, if you run bundle exec foreman run rake assets:precompile , the environment will be production for that task. Don't forget to change it back when you're done! ;-)

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM