# Address server

**URL:** <https://www.ruby-forum.com/t/address-server/80949>\
**Category:** Ruby\
**Created:** [January 2, 2007, 2:21pm UTC](https://www.ruby-forum.com/t/address-server/80949 "2007-01-02T14:21:33Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![marco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a698b9/32.png) [@marco](https://www.ruby-forum.com/u/marco)\
**Post date:** [January 2, 2007, 2:21pm UTC](https://www.ruby-forum.com/t/address-server/80949/1 "2007-01-02T14:21:33Z")

</div>

Hi  
Do you know a method for find address of the server ?  
I have to do an “if” to find if I am in localhost:3000 or in

> **[Web Hosting, Domain Name Registration - MyDomain.com](https://www.mydomain.com/)**
>
> Small business web hosting offering additional business services such as: domain name registrations, email accounts, web services, and various small business solutions.

Thank you an happy new year.  
Marco

---

<div class="post-metadata">

**Author:** ![marco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a698b9/32.png) [@marco](https://www.ruby-forum.com/u/marco)\
**Post date:** [January 2, 2007, 2:35pm UTC](https://www.ruby-forum.com/t/address-server/80949/2 "2007-01-02T14:35:37Z")

</div>

On 02.01.2007 14:19, marco wrote:

> Do you know a method for find address of the server ?  
> I have to do an “if” to find if I am in localhost:3000 or in  
> [mydomain.com](http://mydomain.com)

In what kind of application?

```
robert

```

---

<div class="post-metadata">

**Author:** ![marco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a698b9/32.png) [@marco](https://www.ruby-forum.com/u/marco)\
**Post date:** [January 2, 2007, 3:15pm UTC](https://www.ruby-forum.com/t/address-server/80949/3 "2007-01-02T15:15:45Z")

</div>

In a web application

---

<div class="post-metadata">

**Author:** ![marco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a698b9/32.png) [@marco](https://www.ruby-forum.com/u/marco)\
**Post date:** [January 2, 2007, 4:05pm UTC](https://www.ruby-forum.com/t/address-server/80949/4 "2007-01-02T16:05:50Z")

</div>

On 02.01.2007 15:11, marco wrote:

> In a web application

Often you can get this information from the URL of the current page.

Other than that you can derive this from the socket if you have access  
to it:

[http://ruby-doc.org/stdlib/libdoc/socket/rdoc/classes/Socket.html#M002385](http://ruby-doc.org/stdlib/libdoc/socket/rdoc/classes/Socket.html#M002385)

And, please don’t top post. Thank you!

Kind regards

```
robert

```

---

<div class="post-metadata">

**Author:** ![marco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a698b9/32.png) [@marco](https://www.ruby-forum.com/u/marco)\
**Post date:** [January 2, 2007, 9:01pm UTC](https://www.ruby-forum.com/t/address-server/80949/5 "2007-01-02T21:01:51Z")

</div>

I’m going to make the assumption that we are talking about a Rails app.  
The  
easiest way I found was to call request.host\_with\_port within a  
controller  
or a view. This will return the host name and the port number (if  
provided).

I use this approach to figure out which Google Maps api key to use in my  
application (one for development work, another one for the “production”  
site).

There is a very active mailing list for Ruby on Rails. You can get  
details  
on how to subscribe by going to  
[http://groups.google.com/group/rubyonrails-talk?hl=en](http://groups.google.com/group/rubyonrails-talk?hl=en) .

Hope this helps.

Fred

---

<div class="post-metadata">

**Author:** ![marco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a698b9/32.png) [@marco](https://www.ruby-forum.com/u/marco)\
**Post date:** [January 3, 2007, 7:41am UTC](https://www.ruby-forum.com/t/address-server/80949/6 "2007-01-03T07:41:26Z")

</div>

“marco” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

> 

I’m suspecting your asking the wrong question. Can you expand a bit more  
on  
what exactly you need to do and/or why you need to know this. Also, are  
you  
talking about working this out from the client perspective or from  
within your  
code on the server?

Tim

---

<div class="post-metadata">

**Author:** ![marco](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a698b9/32.png) [@marco](https://www.ruby-forum.com/u/marco)\
**Post date:** [January 3, 2007, 12:46pm UTC](https://www.ruby-forum.com/t/address-server/80949/7 "2007-01-03T12:46:05Z")

</div>

Frederic J. wrote:

> I’m going to make the assumption that we are talking about a Rails app. The  
> easiest way I found was to call request.host\_with\_port within a controller  
> or a view. This will return the host name and the port number (if provided).
> 
> I use this approach to figure out which Google Maps api key to use in my  
> application (one for development work, another one for the “production”  
> site).  
> Me too. This was my trouble.
> 
> There is a very active mailing list for Ruby on Rails. You can get details  
> on how to subscribe by going to  
> [http://groups.google.com/group/rubyonrails-talk?hl=en](http://groups.google.com/group/rubyonrails-talk?hl=en) .
> 
> Hope this helps.
> 
> Fred

I find this method “request.env” who return a hash of all information :  
request.env[“SERVER\_NAME”] and [“SERVER\_PORT”]

Thank for your helps  
Marco
