I am no guru on this topic, but I glanced at the section of the AWDWR that
talks about that; it seems that what you need to do is:
a) override the automatic rails generation of xml
b) and generate the Xml yourself... with the help of Jim Weirich's builder
library
So: after installing the 'builder' gem:
a) in the controller:
def index
@persons = Person.find(:all)
respond_to do |format|
format.html
format.xml { render :layout => false }
end
end
b) in app/views/person/index.builder.xml
xml.persons do
xml.totalcount(@persons.size)
@persons.each do |p|
xml.person do
xml.name(p.name)
...
end
end
end
###
It is a bit unfortunate that just to add a field, we need to generate all
the Xml, but I did not find any other way.
But in any case the above works
Raul
On Fri, Sep 5, 2008 at 5:16 PM, Jack <[EMAIL PROTECTED]> wrote:
>
> Hello,
> ROR Gurus, can anyone help me?
>
> Thanks in Advance!
>
>
> On Sep 3, 10:39 pm, [EMAIL PROTECTED] wrote:
> > Hi,
> > I'm new to Ruby & using ROR as a web service. I'm returning XML
> > using statement:
> >
> > @persons = Person.find(:all)
> > render :xml => persons.to_xml()
> >
> > Now, this returns xml fine without any issues. However, it does not
> > return the number of records. Lets say there are 2 records returned by
> > the query as shown below:
> >
> > <?xml version="1.0" encoding="UTF-8"?>
> > <persons>
> > <person>
> > <fname>Vick</fname>
> > </person>
> > <person>
> > <fname>John</fname>
> > </person>
> > </persons>
> >
> > Now, I need output xml as shown below which will include count as
> > well:
> > <?xml version="1.0" encoding="UTF-8"?>
> > <persons>
> > <totalcount>2</totalcount>
> > <person>
> > <fname>Vick</fname>
> > </person>
> > <person>
> > <fname>John</fname>
> > </person>
> > </persons>
> >
> > Can anyone help me out???
> >
> > Thanks in Advance!
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "ruby-on-rails-programming-with-passion" group.
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/ruby-on-rails-programming-with-passion?hl=en?hl=en
-~----------~----~----~----~------~----~------~--~---