# Best way to know the domain across all controllers?

**URL:** <https://www.ruby-forum.com/t/best-way-to-know-the-domain-across-all-controllers/102460>\
**Category:** Rails\
**Created:** [February 8, 2006, 5:23pm UTC](https://www.ruby-forum.com/t/best-way-to-know-the-domain-across-all-controllers/102460 "2006-02-08T17:23:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![softwareengineer\_99](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b782af/32.png) [@softwareengineer\_99](https://www.ruby-forum.com/u/softwareengineer_99)\
**Post date:** [February 8, 2006, 5:23pm UTC](https://www.ruby-forum.com/t/best-way-to-know-the-domain-across-all-controllers/102460/1 "2006-02-08T17:23:37Z")

</div>

Hello,  
I would like to use something like  
domain=request.domain  
and be able to access the domain variable across all my controllers.

What is the best way to do so? In which file can I put the above  
variable declaration and still be able to access it application wide?

I guess I am asking on assistance for using global variables in rails.

Can anyone please guide me to a source or help me figure this out.

Thanks  
Frank

---

<div class="post-metadata">

**Author:** ![softwareengineer\_99](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b782af/32.png) [@softwareengineer\_99](https://www.ruby-forum.com/u/softwareengineer_99)\
**Post date:** [February 8, 2006, 5:37pm UTC](https://www.ruby-forum.com/t/best-way-to-know-the-domain-across-all-controllers/102460/2 "2006-02-08T17:37:35Z")

</div>

application.rb

def set\_domain  
@domain=request.domain  
end

In your controllers…

before\_filter :set\_domain

All that gets you, though, is the ability to replace:

request.domain

with

@domain

Not worth it, if you ask me.

–  
– Tom M.

---

<div class="post-metadata">

**Author:** ![softwareengineer\_99](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b782af/32.png) [@softwareengineer\_99](https://www.ruby-forum.com/u/softwareengineer_99)\
**Post date:** [February 8, 2006, 8:34pm UTC](https://www.ruby-forum.com/t/best-way-to-know-the-domain-across-all-controllers/102460/3 "2006-02-08T20:34:53Z")

</div>

Hi Tom,  
Thank you for your reply.  
I was interested in understanding the concept so your reply did help.

Thanks  
Frank

Tom M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote: Not worth it, if you ask  
me.
