我正在使用Ruby on Rails 3,我正在尝试设置JSON/XML响应的值.
在我的控制器中我有
respond_to do |format|
format.xml { render :xml => @user.to_xml }
format.json { render :json => @user.to_json }
end
Run Code Online (Sandbox Code Playgroud)
当我为JSON/XML发出HTTP GET请求时,会设置这些常用值
header:
date:
- Fri, 18 Feb 2011 18:02:55 GMT
server:
- Apache ...
etag:
- "\"0dbfd0ec23934921144bd57d383db443\""
cache-control:
- max-age=0, private, must-revalidate
x-ua-compatible:
- IE=Edge
x-runtime:
- "0.033209"
status:
- "200"
transfer-encoding:
- chunked
content-type:
- application/json; charset=utf-8 #or application/xml; charset=utf-8
http_version: "1.1"
message: OK
read: true
Run Code Online (Sandbox Code Playgroud)
我想添加/设置header
值并添加像message2
或的新参数header2
.
我怎么能用format.json/xml …