Created
February 28, 2014 16:39
-
-
Save amxn/9274332 to your computer and use it in GitHub Desktop.
Generate a CSV from a collection action.
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
collection_action :download_report, method: :get do | |
users = User.where('created_at >= ?', Date.today - 1.month) | |
csv = CSV.generate( encoding: 'Windows-1251' ) do |csv| | |
# add headers | |
csv << [ #Some header ] | |
# add data | |
users.each do |user| | |
csv << [ user.created_at ] | |
end | |
end | |
# send file to user | |
send_data csv.encode('Windows-1251'), type: 'text/csv; charset=windows-1251; header=present', disposition: "attachment; filename=report.csv" | |
end | |
action_item only: :index do | |
link_to "csv report", download_report_admin_#{models}_path, method: :get | |
end | |
index download_links: false do | |
# off standard download link | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment