4

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?

RubyRedGrapefruit
  • 12,066
  • 16
  • 92
  • 193

2 Answers2

10
Rails.env = 'staging'

Put this in your task file.

Mike Lewis
  • 63,433
  • 20
  • 141
  • 111
7

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!

Xavier Holt
  • 14,471
  • 4
  • 43
  • 56