简体   繁体   English

在Rails环境中,当前请求对象的绝对路径是什么?

[英]What's the absolute path to current request object in Rails environment?

I'm searching for the current request of class Rack::Request to find the params. 我正在搜索Rack::Request类的当前请求以找到参数。 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. 我不知道如何找到可能包含该信息的ApplicationControllerRack::Server任何实例。

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. 另外,认为进入日志的工作量太大,因此我希望将精力集中在查找请求对象上,而不是告诉我通过日志进行grep /搜索。

In hopes of being able to be lazy, 希望能够变得懒惰,
Love Dzhon. 爱Dzhon。

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. 可能是我误解了您的问题,但是从控制器内部,您可以简单地访问request对象以获取其详细信息,并可以通过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. 例如,如果要使请求对象可用于模型,则可以创建类访问器并将其存储在任何操作的开始处(例如,通过应用程序控制器中的before_filter )。 More details why here . 为什么在这里更多细节。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM