ruby on rails - How to set headers of a JSON/XML response in 'format.json/xml { render :json/xml => @user.to_json/xml }'? -
i using ruby on rails 3 , trying set values of json/xml response.
in controller have
respond_to |format| format.xml { render :xml => @user.to_xml } format.json { render :json => @user.to_json } end
when make http request json/xml, set common values these
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
i add/set header
values , add new parameters message2
or header2
.
how can in format.json/xml { render :json/xml => @user.to_json/xml }
syntax?
the format.foo { render ... }
thing takes block. can put whatever want there:
format.json response['x-message-1'] = 'hello' render :json => @user.to_json end
Comments
Post a Comment