Skip to content

Instantly share code, notes, and snippets.

@jordangraft
Last active April 24, 2016 21:04
Show Gist options
  • Save jordangraft/12da6954be6b24d58af104d6718c6b57 to your computer and use it in GitHub Desktop.
Save jordangraft/12da6954be6b24d58af104d6718c6b57 to your computer and use it in GitHub Desktop.
class OrdersController < ApplicationController
def index
...
respond_to do |format|
format.json { render :index }
format.csv { send_data build_csv, filename: "Orders-#{Date.today}.csv" }
end
end
private
def build_csv
CSV.generate do |csv|
csv << Order.csv_columns
@orders.each { |order| csv << order.to_csv }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment