-1

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?

luchaninov
  • 5,986
  • 6
  • 53
  • 75
ZachyBear
  • 157
  • 2
  • 14
  • What kind of database are you using? SQLite? If so, you may find this post useful: http://stackoverflow.com/questions/6076984/how-to-export-the-results-of-my-query-to-csv-file-sqlite. Excel can easily handle CSV files. – Nicholas Flees Apr 14 '14 at 17:38
  • Sorry. Didn't notice that you tagged the post with mysql. This answer should help: http://stackoverflow.com/a/356605/868691 – Nicholas Flees Apr 14 '14 at 17:44

1 Answers1

2

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

http://guides.rubyonrails.org/layouts_and_rendering.html#using-render

So for example, in your controller:

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

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

http://railscasts.com/episodes/362-exporting-csv-and-excel

Jakub K
  • 1,645
  • 1
  • 12
  • 20