Last active
April 24, 2016 21:04
-
-
Save jordangraft/12da6954be6b24d58af104d6718c6b57 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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