# Can we get request in application controller?

**URL:** <https://www.ruby-forum.com/t/can-we-get-request-in-application-controller/130180>\
**Category:** Rails\
**Created:** [February 26, 2008, 4:12am UTC](https://www.ruby-forum.com/t/can-we-get-request-in-application-controller/130180 "2008-02-26T04:12:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kopf1988](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/74df32/32.png) [@kopf1988](https://www.ruby-forum.com/u/kopf1988)\
**Post date:** [February 26, 2008, 4:12am UTC](https://www.ruby-forum.com/t/can-we-get-request-in-application-controller/130180/1 "2008-02-26T04:12:49Z")

</div>

Hi, I’m trying to use my application controller to define my website  
object (thus helping me find which template to use, etc).

I have this code in ApplicationController

sitename = request.host  
sitename = “www.” + sitename unless sitename.split(’.’)[2]  
$website = Website.find\_by\_title( sitename )

but I get undefined local variable or method `request’ for  
ApplicationController:Class

Any ideas?

---

<div class="post-metadata">

**Author:** ![kopf1988](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/74df32/32.png) [@kopf1988](https://www.ruby-forum.com/u/kopf1988)\
**Post date:** [February 26, 2008, 5:36am UTC](https://www.ruby-forum.com/t/can-we-get-request-in-application-controller/130180/2 "2008-02-26T05:36:34Z")

</div>

> ApplicationController:Class
> 
> Any ideas?

You have it directly in ApplicationController? That’s probably not what  
you want.

You probably want this:

class ApplicationController \< ActionController::Base

before\_filter :determine\_website

private  
def determine\_website  
sitename = request.host  
sitename = “www.” + sitename unless sitename.split(’.’)[2]  
@website = Website.find\_by\_title( sitename )  
end

end

Then you can reference @website in your actions and views.

-philip
