# Get which enviornment is running from controller

**URL:** <https://www.ruby-forum.com/t/get-which-enviornment-is-running-from-controller/109500>\
**Category:** Rails\
**Created:** [July 15, 2007, 11:00pm UTC](https://www.ruby-forum.com/t/get-which-enviornment-is-running-from-controller/109500 "2007-07-15T23:00:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ktheory](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@ktheory](https://www.ruby-forum.com/u/ktheory)\
**Post date:** [July 15, 2007, 11:00pm UTC](https://www.ruby-forum.com/t/get-which-enviornment-is-running-from-controller/109500/1 "2007-07-15T23:00:06Z")

</div>

how can I get what enviornment is currently running from a controller?..  
like development, test, production, etc.

thanks…

---

<div class="post-metadata">

**Author:** ![ktheory](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@ktheory](https://www.ruby-forum.com/u/ktheory)\
**Post date:** [July 15, 2007, 11:42pm UTC](https://www.ruby-forum.com/t/get-which-enviornment-is-running-from-controller/109500/2 "2007-07-15T23:42:25Z")

</div>

I’d like to know this also. I need to know how force a rake task to  
pick up an environment other than ‘production’ on my production host.  
I renamed my environment to something more specific, but “rake  
db:migrate” always uses the configuration under the “production”  
environment…

On Jul 15, 2:00 pm, Aaron S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![ktheory](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@ktheory](https://www.ruby-forum.com/u/ktheory)\
**Post date:** [July 15, 2007, 11:59pm UTC](https://www.ruby-forum.com/t/get-which-enviornment-is-running-from-controller/109500/3 "2007-07-15T23:59:26Z")

</div>

Ah, google actually had the answer to my question:  
rake db:migrate RAILS\_ENV=my\_production\_env

---

<div class="post-metadata">

**Author:** ![ktheory](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@ktheory](https://www.ruby-forum.com/u/ktheory)\
**Post date:** [July 16, 2007, 12:03am UTC](https://www.ruby-forum.com/t/get-which-enviornment-is-running-from-controller/109500/4 "2007-07-16T00:03:57Z")

</div>

zaven wrote:

> Ah, google actually had the answer to my question:  
> rake db:migrate RAILS\_ENV=my\_production\_env

I’m looking to find out how you access this in a controller. is it still  
RAILS\_ENV?

---

<div class="post-metadata">

**Author:** ![ktheory](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@ktheory](https://www.ruby-forum.com/u/ktheory)\
**Post date:** [July 16, 2007, 12:56am UTC](https://www.ruby-forum.com/t/get-which-enviornment-is-running-from-controller/109500/5 "2007-07-16T00:56:06Z")

</div>

if you take a look at your rails gem.  
in rails/lib/initializer.rb, line 12-ish,  
there’s the following;

RAILS\_ENV = (ENV[‘RAILS\_ENV’] || ‘development’).dup unless  
defined?(RAILS\_ENV)

So,  
indeed,  
calling RAILS\_ENV from anywhere inside you app will return the  
environment.

Aaron S. wrote:

> zaven wrote:
> 
> > Ah, google actually had the answer to my question:  
> > rake db:migrate RAILS\_ENV=my\_production\_env
> 
> I’m looking to find out how you access this in a controller. is it still  
> RAILS\_ENV?
