# Environment Variable for Ruby on Rails

**URL:** <https://www.ruby-forum.com/t/environment-variable-for-ruby-on-rails/48422>\
**Category:** Ruby\
**Created:** [November 20, 2005, 5:08am UTC](https://www.ruby-forum.com/t/environment-variable-for-ruby-on-rails/48422 "2005-11-20T05:08:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomrossi7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c4cdca/32.png) [@tomrossi7](https://www.ruby-forum.com/u/tomrossi7)\
**Post date:** [November 20, 2005, 5:08am UTC](https://www.ruby-forum.com/t/environment-variable-for-ruby-on-rails/48422/1 "2005-11-20T05:08:56Z")

</div>

Is there an entry in the request.env hash for the host header? I can  
parse the request.env[“REQUEST\_URI”], but I was just wondering. I  
couldn’t find any documentation on the contents of that hash –  
[Peak Obsession](http://api.rubyonrails.com/classes/ActionController/Base.html) appears  
to only show a couple of the keys.

Thanks!  
Tom

---

<div class="post-metadata">

**Author:** ![tomrossi7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c4cdca/32.png) [@tomrossi7](https://www.ruby-forum.com/u/tomrossi7)\
**Post date:** [November 20, 2005, 5:37am UTC](https://www.ruby-forum.com/t/environment-variable-for-ruby-on-rails/48422/2 "2005-11-20T05:37:06Z")

</div>

-----BEGIN PGP SIGNED MESSAGE-----  
Hash: SHA1

On Nov 19, 2005, at 8:07 PM, TomRossi7 wrote:

> Is there an entry in the request.env hash for the host header?

request.host is the method you’re looking for. See the docs for  
AbstractRequest for some other convenient methods such as subdomains  
and remote\_ip (which resolves proxied addresses for you.)

Regards,  
jeremy  
-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v1.4.2 (Darwin)

iD8DBQFDf/0oAQHALep9HFYRAlMCAKCqQrXgwo0xosMZWW7fL9xayTDsRACcCI+N  
S8ZDSVQC6Ml01VsPd5NQQfM=  
=AxT9  
-----END PGP SIGNATURE-----

---

<div class="post-metadata">

**Author:** ![tomrossi7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c4cdca/32.png) [@tomrossi7](https://www.ruby-forum.com/u/tomrossi7)\
**Post date:** [November 20, 2005, 6:49am UTC](https://www.ruby-forum.com/t/environment-variable-for-ruby-on-rails/48422/3 "2005-11-20T06:49:33Z")

</div>

You can use the magical .inspect on the request.env hash like so:  
request.env.inspect to find out anything about the internals of a hash.

script/console will work pretty well for that kind of debugging.

Warmest regards,  
Nathan.

* * *

Nathaniel S. H. Brown Toll Free 1.877.4.INIMIT  
Inimit Innovations Phone 604.724.6624  
[www.inimit.com](http://www.inimit.com) Fax 604.444.9942

---

<div class="post-metadata">

**Author:** ![tomrossi7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c4cdca/32.png) [@tomrossi7](https://www.ruby-forum.com/u/tomrossi7)\
**Post date:** [November 20, 2005, 7:10pm UTC](https://www.ruby-forum.com/t/environment-variable-for-ruby-on-rails/48422/4 "2005-11-20T19:10:35Z")

</div>

…inspect is very useful indeed! Thanks!

---

<div class="post-metadata">

**Author:** ![tomrossi7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c4cdca/32.png) [@tomrossi7](https://www.ruby-forum.com/u/tomrossi7)\
**Post date:** [November 21, 2005, 3:29am UTC](https://www.ruby-forum.com/t/environment-variable-for-ruby-on-rails/48422/5 "2005-11-21T03:29:43Z")

</div>

Perfect! Unfortunately, I can’t seem to find the documentation though  
for it?  
[http://api.rubyonrails.org/classes/ActionController/AbstractRequest.html](http://api.rubyonrails.org/classes/ActionController/AbstractRequest.html)  
talks about some methods, but not request.host.

The only reason I ask is because now I want to pull back the Session  
Id. I don’t see a straight-forward way to get it?

Thanks,  
Tom

---

<div class="post-metadata">

**Author:** ![tomrossi7](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/c4cdca/32.png) [@tomrossi7](https://www.ruby-forum.com/u/tomrossi7)\
**Post date:** [November 21, 2005, 4:33am UTC](https://www.ruby-forum.com/t/environment-variable-for-ruby-on-rails/48422/6 "2005-11-21T04:33:59Z")

</div>

-----BEGIN PGP SIGNED MESSAGE-----  
Hash: SHA1

On Nov 20, 2005, at 6:27 PM, TomRossi7 wrote:

> [http://api.rubyonrails.org/classes/ActionController/](http://api.rubyonrails.org/classes/ActionController/)  
> AbstractRequest.html  
> talks about some methods, but not request.host.

An oversight; its documentation is exposed the next release.

> The only reason I ask is because now I want to pull back the Session  
> Id. I don’t see a straight-forward way to get it?

In a controller, session.session\_id

Please take further discussion to the Rails list. Thanks!

jeremy  
-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v1.4.2 (Darwin)

iD8DBQFDgT9TAQHALep9HFYRApKEAJ9w6F2VGfIs3OpceD40GXWGX5rF6wCfa8xG  
ic7N65uLC+/5PK/ExtBOqcs=  
=rWw6  
-----END PGP SIGNATURE-----
