incubator-deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tong Li <liton...@us.ibm.com>
Subject DeltaCloud Haml use
Date Fri, 02 Sep 2011 15:02:07 GMT

When implementing RESTful APIs, often you have to support both XML and JSON
(sometimes also ATOM Feed), Ruby has nice functions to convert between XML
and JSON. In DeltaCloud, very often see code like this.


	respond_to do |format|

		format.html {haml :"index" }
		format.xml  {haml :"index" }
		format.json { haml :"index" }

	end

	is there anyway to use some thing like this.

	respond_to do |format|

		format.html {haml :"index" }
		format.xml  {haml :"index" }
		format.json do
			get the xml data,
			then convert it to json, by using Hash.from_xml(the
stream).to_json
	                end
	end

	This is to ensure that the json format contains absolutely same
information as in xml format and only provide one xml haml file, the
problem is that now I do not know how to change the request so that the
template searches for index.xml.haml rather than index.json.haml when
request for json. I think there should be a way to do this, but within DC
rabbit, I do not know if there is an easy way. of course, hash data can be
directly converted to json, but sometimes, the xml haml may take in data
from more than one objects, it will be a lot easier to simply direct the
request to xml and get the xml object then convert it to json or even feed,
Any pointer will be appreciated.

Thanks.

Tong Li
Emerging Technologies & Standards
B062/K317
litong01@us.ibm.com
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message