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 ne开发者_如何学Goed to run anything as the development environment on that server. How can I make rake tasks run in the "staging" environment by default?
Rails.env = 'staging'
Put this in your task file.
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!
精彩评论