# Is there a way to set a global variable in my deploy

**URL:** <https://www.ruby-forum.com/t/is-there-a-way-to-set-a-global-variable-in-my-deploy/186755>\
**Category:** Deployment\
**Created:** [February 25, 2008, 8:19pm UTC](https://www.ruby-forum.com/t/is-there-a-way-to-set-a-global-variable-in-my-deploy/186755 "2008-02-25T20:19:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lucasc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/6a8cbe/32.png) [@lucasc](https://www.ruby-forum.com/u/lucasc)\
**Post date:** [February 25, 2008, 8:19pm UTC](https://www.ruby-forum.com/t/is-there-a-way-to-set-a-global-variable-in-my-deploy/186755/1 "2008-02-25T20:19:32Z")

</div>

I am deploying an application to several sub domains and need to set a  
global variable in each sub domain so that I query the correct table  
based on the sub domain. Currently I am doing this in my layouts but  
this doesn’t seem like a good practice.

Does anyone know of a way to set this global variable when I deploy  
using capistrano?

---

<div class="post-metadata">

**Author:** ![lucasc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/6a8cbe/32.png) [@lucasc](https://www.ruby-forum.com/u/lucasc)\
**Post date:** [February 25, 2008, 8:26pm UTC](https://www.ruby-forum.com/t/is-there-a-way-to-set-a-global-variable-in-my-deploy/186755/2 "2008-02-25T20:26:56Z")

</div>

On Mon, 2008-02-25 at 20:19 +0100, Lucas Campbell wrote:

> I am deploying an application to several sub domains and need to set a  
> global variable in each sub domain so that I query the correct table  
> based on the sub domain.

Hm, sounds like something you could do in a controller - just check the  
“Host” header of the incoming HTTP request.

Yours,

tom

---

<div class="post-metadata">

**Author:** ![lucasc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/6a8cbe/32.png) [@lucasc](https://www.ruby-forum.com/u/lucasc)\
**Post date:** [February 25, 2008, 8:49pm UTC](https://www.ruby-forum.com/t/is-there-a-way-to-set-a-global-variable-in-my-deploy/186755/3 "2008-02-25T20:49:56Z")

</div>

Tom C. wrote:

> On Mon, 2008-02-25 at 20:19 +0100, Lucas Campbell wrote:
> 
> > I am deploying an application to several sub domains and need to set a  
> > global variable in each sub domain so that I query the correct table  
> > based on the sub domain.
> 
> Hm, sounds like something you could do in a controller - just check the  
> “Host” header of the incoming HTTP request.
> 
> Yours,
> 
> tom

I actually created a helper method that uses url\_for to grab the url and  
find out which subdomain its in and then set the global variable  
accordingly.

I can’t access helper methods from my controller so I am using my layout  
to call my helper method which sets the global varialbe. Only thing is,  
since i call the helper from my layout, it is being called every time a  
page is rendered.

I wanted to find a way to add something in my deploy.rb file to call the  
helper method once so the global is set.

---

<div class="post-metadata">

**Author:** ![lucasc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/6a8cbe/32.png) [@lucasc](https://www.ruby-forum.com/u/lucasc)\
**Post date:** [February 25, 2008, 9:14pm UTC](https://www.ruby-forum.com/t/is-there-a-way-to-set-a-global-variable-in-my-deploy/186755/4 "2008-02-25T21:14:57Z")

</div>

On Mon, 2008-02-25 at 20:49 +0100, Lucas Campbell wrote:

> helper method once so the global is set.  
> Ah, I see. You could do an after :update\_code task that appends a  
> variable declaration to your environment.rb file or puts a file in  
> shared/system/… hm, I wonder if you could just look at your RAILS\_ROOT  
> from within the app and key off the directory names embedded there?

Yours,

tom
