I want to respond with json and xml in my ruby on rails app.
In my controller (e.g “Person”) I have:
respond_to :html, :json, :xml
In the show-method:
@person = Person.find(params[:id])
respond_with @person
In my Person-Model I define a ‘as_json’ and a ‘as_xml’ method, because I want to include data.
def as_json(options={})
super(:include => :parents)
end
def as_xml(options={})
super(:include => :parents)
end
The call /persons/1.json is correct.
But the call /persons/1.xml gives me only the person attributes as an xml. The include is missing.
I can’t find informations for xml, only for json. Is it possible to use as_xml?
Maybe you are searching for to_xml