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?
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?
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.