# Host\_with\_port in config/environment.rb

**URL:** <https://www.ruby-forum.com/t/host-with-port-in-config-environment-rb/178794>\
**Category:** Rails\
**Created:** [November 11, 2009, 1:01pm UTC](https://www.ruby-forum.com/t/host-with-port-in-config-environment-rb/178794 "2009-11-11T13:01:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![shark83](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ac91a4/32.png) [@shark83](https://www.ruby-forum.com/u/shark83)\
**Post date:** [November 11, 2009, 1:01pm UTC](https://www.ruby-forum.com/t/host-with-port-in-config-environment-rb/178794/1 "2009-11-11T13:01:00Z")

</div>

Hello everyone… i’m Italian, sorry for my poor English, but I find  
myself in difficulties with this method.I don’t need to redirect the  
logout of rubycas in a host other than localhost… when the decoy in  
“config/environment.rb” of course tells me ‘method ‘host\_with\_port’  
undefined’… I looked in the folder of ruby and i saw that it is  
defined in  
Ruby\lib\ruby\gems\1.8\gems\actionpack-2.3.4\lib\action\_controller\request.rb,  
then to invoke it I did the following:

require ‘actionpack’  
ActionController.host\_with\_port

and gives me this error: “undefined method ‘host\_with\_port’ for  
ActionController::Module (NoMethodError)”. How do you? It is defined  
precisely in that module… I hope that to help me because I do not come  
out.  
PS: I use rails 2.3.4

---

<div class="post-metadata">

**Author:** ![shark83](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ac91a4/32.png) [@shark83](https://www.ruby-forum.com/u/shark83)\
**Post date:** [November 11, 2009, 2:34pm UTC](https://www.ruby-forum.com/t/host-with-port-in-config-environment-rb/178794/2 "2009-11-11T14:34:25Z")

</div>

Enrico M. wrote:

> Hello everyone… i’m Italian, sorry for my poor English, but I find  
> myself in difficulties with this method.I don’t need to redirect the  
> logout of rubycas in a host other than localhost… when the decoy in  
> “config/environment.rb” of course tells me ‘method ‘host\_with\_port’  
> undefined’… I looked in the folder of ruby and i saw that it is  
> defined in  
> Ruby\lib\ruby\gems\1.8\gems\actionpack-2.3.4\lib\action\_controller\request.rb,  
> then to invoke it I did the following:
> 
> require ‘actionpack’  
> ActionController.host\_with\_port
> 
> and gives me this error: “undefined method ‘host\_with\_port’ for  
> ActionController::Module (NoMethodError)”. How do you? It is defined  
> precisely in that module… I hope that to help me because I do not come  
> out.  
> PS: I use rails 2.3.4

I noticed that the host\_with\_port method works safely all controller or  
view, but if I go to use it in config/environment.rb setting a filter  
rubycas logout so:

CASClient: Frameworks:Rails: configure () Filter.  
: logout\_url =  
“[https://mioservercas/logout?service=http://#{host\_with\_port}/](https://mioservercas/logout?service=http://#%7Bhost_with_port%7D/)”  
}

tells me that the host\_with\_port method is undefined… I do the require  
something? I repeat that this method don’t works only in  
config/environment.rb. I hope have been clearer.

---

<div class="post-metadata">

**Author:** ![shark83](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ac91a4/32.png) [@shark83](https://www.ruby-forum.com/u/shark83)\
**Post date:** [November 11, 2009, 5:19pm UTC](https://www.ruby-forum.com/t/host-with-port-in-config-environment-rb/178794/3 "2009-11-11T17:19:31Z")

</div>

I must configure rubycas logout so:

CASClient::Frameworks::Rails::Filter.configure(  
:cas\_base\_url =\> “[https://myservercas/](https://myservercas/)”,  
…  
:logout\_url =\>  
“[https://myservercas/logout?service=http://#{request.host\_with\_port}](https://myservercas/logout?service=http://#%7Brequest.host_with_port%7D)”,  
…  
)

and to do so I must change config/environment.rb,but in this file tell  
me that the request.host\_with\_port method is undefined…help me ☹

---

<div class="post-metadata">

**Author:** ![shark83](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ac91a4/32.png) [@shark83](https://www.ruby-forum.com/u/shark83)\
**Post date:** [November 11, 2009, 8:03pm UTC](https://www.ruby-forum.com/t/host-with-port-in-config-environment-rb/178794/4 "2009-11-11T20:03:53Z")

</div>

Frederick C. wrote:

> On Nov 11, 4:19ï¿½pm, Enrico M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > and to do so I must change config/environment.rb,but in this file tell  
> > me that the request.host\_with\_port method is undefined…help me ☹
> 
> host\_with\_port is an instance method on an individual request - you  
> can’t call it if you are not in the presence of an individual  
> request.
> 
> Fred

ok but if i use this method so:

line50:$hostname= request.host\_with\_port  
line51:CASClient::Frameworks::Rails::Filter.configure(  
line52:…  
line53: :logout\_url =\>  
line54: “[https://myservercas/logout?service=http://#{$hostname}](https://myservercas/logout?service=http://#%7B$hostname%7D)”,  
line55:…  
line56:)

gives me the same error(undefined method request…at line50).I’m in the  
presence of a request here.I couldn’t use “request” and “host\_with\_port”  
in environment.rb,because they are undefined.Why? ☹

---

<div class="post-metadata">

**Author:** ![shark83](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ac91a4/32.png) [@shark83](https://www.ruby-forum.com/u/shark83)\
**Post date:** [November 11, 2009, 7:08pm UTC](https://www.ruby-forum.com/t/host-with-port-in-config-environment-rb/178794/5 "2009-11-11T19:08:47Z")

</div>

On Nov 11, 4:19 pm, Enrico M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> and to do so I must change config/environment.rb,but in this file tell  
> me that the request.host\_with\_port method is undefined…help me ☹

host\_with\_port is an instance method on an individual request - you  
can’t call it if you are not in the presence of an individual  
request.

Fred
