2

I'm searching for the current request of class Rack::Request to find the params. Suppose I've spawned a debugger in my model, I don't want to send a new request, but still find my params.

I couldn't find any class attributes, that would store current request, which is reasonable.
I don't know how to find any instances of ApplicationController or Rack::Server, which might contain the info.

Also, peaking into the log is considered too much effort, so I'd like the effort to be concentrated on finding the request object, not telling me to grep/search through log.

In hopes of being able to be lazy,
Love Dzhon.

galva
  • 1,253
  • 10
  • 17

1 Answers1

0

It's possible I'm misunderstanding your question, but from within a controller you can simply access a request object to get its details, and params to get the params.

ItemController
  def show
    @page_variable = request.inspect + params.inspect
  end
end

If you want to make the request object available to your models you can create a class accessor and store it at the beginning of any action (via a before_filter in the application controller) for example. More details why here.

Community
  • 1
  • 1
Matt
  • 13,948
  • 6
  • 44
  • 68
  • I'm not in the controller, I do not have indirect access to the controller instance. – galva Jun 12 '13 at 12:54
  • If you're looking for a request then presumably you have come from a controller at some point, you can pass the request object down to your models, or store it in a class accessor for use by models, perhaps? – Matt Jun 12 '13 at 12:55
  • Yes, I can, but that's not what I care for or want to do. I want the absolute path to getting the request object. – galva Jun 12 '13 at 12:58
  • 1
    You can't directly get the current request from inside a model without passing it down from the controllers in some fashion, models just aren't meant to do that. You can however store the current request object in an accessible location at the beginning of every request, see [this question](http://stackoverflow.com/questions/6307138/how-do-i-get-request-uri-in-model-in-rails) for more opinions on this matter. – Matt Jun 12 '13 at 13:02