RubyRedGrapefruit
RubyRedGrapefruit

Reputation: 12224

How can I make rake tasks run in an environment other than dev?

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?

Upvotes: 4

Views: 5852

Answers (2)

Mike Lewis
Mike Lewis

Reputation: 64177

Rails.env = 'staging'

Put this in your task file.

Upvotes: 10

Xavier Holt
Xavier Holt

Reputation: 14619

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!

Upvotes: 7

Related Questions