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

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -