ZachyBear ZachyBear - 1 year ago 86
SQL Question

Exporting data from Rails into XML and Excel

I use RubyOnRails and I want to get the data from within my database into an XML or Excel format.

How can I do it?

Answer Source

Exporting to XML is simple, you can call to_xml method on your items and render the result or use render :xml

So for example, in your controller:

respond_to do |format|
    format.xml { render xml: @items }

When it comes to Excel, there is a railscast on exporting to CSV (which can be easily imported to Excel) and XLS.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download