# AbstractRequest request methods outside of Application.rb

**URL:** <https://www.ruby-forum.com/t/abstractrequest-request-methods-outside-of-application-rb/121809>\
**Category:** Rails\
**Created:** [December 1, 2007, 6:04am UTC](https://www.ruby-forum.com/t/abstractrequest-request-methods-outside-of-application-rb/121809 "2007-12-01T06:04:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![enchanter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ce7236/32.png) [@enchanter](https://www.ruby-forum.com/u/enchanter)\
**Post date:** [December 1, 2007, 6:04am UTC](https://www.ruby-forum.com/t/abstractrequest-request-methods-outside-of-application-rb/121809/1 "2007-12-01T06:04:29Z")

</div>

I’m trying to access methods like request.request\_uri and request.domain  
outside of the normal application and view code. How might one access  
these with code in /lib?

---

<div class="post-metadata">

**Author:** ![enchanter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ce7236/32.png) [@enchanter](https://www.ruby-forum.com/u/enchanter)\
**Post date:** [December 1, 2007, 7:18am UTC](https://www.ruby-forum.com/t/abstractrequest-request-methods-outside-of-application-rb/121809/2 "2007-12-01T07:18:57Z")

</div>

On Nov 30, 2007, at 9:04 PM, Tim Michaud wrote:

> I’m trying to access methods like request.request\_uri and  
> request.domain  
> outside of the normal application and view code. How might one access  
> these with code in /lib?

pass those from your controller into the methods you’re calling.

#------------------

# /controllers/whatever\_controller.rb

class WhateverController \< ActionController::Base

```
 @some_var = LibThing.new
 @some_var.some_lib_method(self.request.subdomains)

```

end

#------------------

# /lib/lib\_thing.rb

class LibThing

def some\_lib\_method(subdomains)  
# does stuf with request.subdomains here  
end

end

–  
def gw  
acts\_as\_n00b  
writes\_at(www.railsdev.ws)  
end

---

<div class="post-metadata">

**Author:** ![enchanter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ce7236/32.png) [@enchanter](https://www.ruby-forum.com/u/enchanter)\
**Post date:** [December 2, 2007, 9:10pm UTC](https://www.ruby-forum.com/t/abstractrequest-request-methods-outside-of-application-rb/121809/3 "2007-12-02T21:10:07Z")

</div>

Greg W. wrote:

> pass those from your controller into the methods you’re calling.

Hey Greg, thanks for the idea. I have tried this and it works well, but  
I’ve run into two problems.

1. I need to call this method about 5-20 times per request, so I’d like  
to be able to abstract the value out and not have to pass the same value  
for each call. (The method does take 2 other parameters, so each call is  
different).

2. But the bigger issue is that I’m finding that i need to call the  
“some\_lib\_method” in “/lib/lib\_thing.rb” from other code in /lib - like  
in “/lib/other\_lib\_thing.rb”.

So what I’m wondering is, is there a way to include or require  
ActionController::AbstractRequest or something similar in  
“/lib/lib\_thing.rb” so that its methods have direct access to  
request.request\_uri and the like?
