How can I make rake tasks run in an environment ot

2019-02-19 02:54发布

I have a staging machine with a special "staging" environment. I always forget to run rake tasks on that machine like:

rake jobs:work RAILS_ENV=staging

So instead I end up doing:

rake jobs:work

And then I'm mystified why nothing has changed in my database. Doh! It's because I didn't remember to supply RAILS_ENV=staging.

But I will never, ever need to run anything as the development environment on that server. How can I make rake tasks run in the "staging" environment by default?

2条回答
再贱就再见
2楼-- · 2019-02-19 03:47

You can put a line that sets the environment variable RAILS_ENV in a file that will get run when you log onto the machine. For example, I'm a bash user, so I'd put the line

export RAILS_ENV=staging

In either ~/.bashrc (just for me) or /etc/bashrc (for everyone who logs onto the machine).

Hope this helps!

查看更多
▲ chillily
3楼-- · 2019-02-19 03:55
Rails.env = 'staging'

Put this in your task file.

查看更多
登录 后发表回答