I have a method called “revisions”, and I want to be able use the same logic but output to csv. I think I’d like to use the FasterCSV gem. What I need is to what to add to my routes in order to get a route for both the html and the csv outputs. I’d like my urls to be something like this:
invoices/51/revisions
invoices/51/revisions.csv
Thoughts?
Thanks much!
Rails makes this very easy. You don’t need to change your routes at all to accommodate CSV format, since rails recognizes the csv MIME-type.
First, set up a route in routes.rb:
In your controller, do something like this:
Here’s a tutorial with more detailed info on formatting the csv files using csvbuilder:
http://rubyglasses.blogspot.com/2009/07/csv-views-with-fastercsv-and-csvbuilder.html