# Best way to tell if you're running in a webapp environment?

**URL:** <https://www.ruby-forum.com/t/best-way-to-tell-if-youre-running-in-a-webapp-environment/190508>\
**Category:** Rails\
**Created:** [June 21, 2010, 10:24pm UTC](https://www.ruby-forum.com/t/best-way-to-tell-if-youre-running-in-a-webapp-environment/190508 "2010-06-21T22:24:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mat\_b](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b77776/32.png) [@mat\_b](https://www.ruby-forum.com/u/mat_b)\
**Post date:** [June 21, 2010, 10:24pm UTC](https://www.ruby-forum.com/t/best-way-to-tell-if-youre-running-in-a-webapp-environment/190508/1 "2010-06-21T22:24:09Z")

</div>

Hi all,

Is there a recommended way to tell from within your Rails app whether  
the app is running as a webapp vs. some other environment (rake task,  
console, background worker, etc.)? I can’t think of anything better  
than just grepping $0, but that seems pretty fragile.

Thanks!  
Mat

---

<div class="post-metadata">

**Author:** ![mat\_b](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b77776/32.png) [@mat\_b](https://www.ruby-forum.com/u/mat_b)\
**Post date:** [June 21, 2010, 11:52pm UTC](https://www.ruby-forum.com/t/best-way-to-tell-if-youre-running-in-a-webapp-environment/190508/2 "2010-06-21T23:52:32Z")

</div>

Hi Mat,

On Mon, Jun 21, 2010 at 3:22 PM, Mat B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi all,
> 
> Is there a recommended way to tell from within your Rails app whether  
> the app is running as a webapp vs. some other environment (rake task,  
> console, background worker, etc.)? I can’t think of anything better  
> than just grepping $0, but that seems pretty fragile

Take a look at the ActionController::Request methods. The request  
headers would be where I’d start. Seems like request.remote\_ip should  
let you know whether requests are coming from inside or outside your  
server.

HTH,  
Bill
