AbstractRequest request methods outside of Application.rb

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?

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

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?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs