新手问题 9.2 The response Object 请求翻译

346617552 · 2012年10月09日 · 最后由 lgn21st 回复于 2012年10月09日 · 2642 次阅读

中文 Guides 里的一团乱,看不懂。那个长句看不懂了。 如果不吝惜指教的话,麻烦翻译一下下文,非常感谢。

9.2 The response Object

The response object is not usually used directly, but is built up during the execution of the action and rendering of the data that is being sent back to the user, but sometimes - like in an after filter - it can be useful to access the response directly. Some of these accessor methods also have setters, allowing you to change their values.

你能给出原文的 URL 么?是英文 Guides 里面的哪一篇?

@lgn21st 这是中文 Guides 里的翻译,麻烦翻到 9.2

这是英文 9.2 那一段

我不太确定用中文应该怎么翻译,但是意思大概能够理解。

这里的是说在 controller 中的 action 处理完用户的请求,并将需要返回给用户的数据渲染完毕后,会将结果保存到当前 controller 的 response 对象中,然后在将结果返回给用户。通常情况下你不需要直接去访问这个 response 对象,但是在一些特定时候,比如 controller 的 after filter 中是可以去直接访问这个对象的,这个对象上提供了一些 accessor 方法可以让你取得对象中保存的数据,以及提供了一些 set 方法让你可以直接修改对象中保存的数据。

@lgn21st 非常感谢,不过还是有点抽象。以后倒回来再理解吧~

#4 楼 @346617552 简单的说,你可以在你的 controller 里面添加下面这个代码,然后到 Log 中看看 response object 长什么样子:

after_filter :show_response_object, :only => [:index]

def show_response_boject
  Rails.logger.info @response.inspect
end
需要 登录 后方可回复, 如果你还没有账号请 注册新账号