Created
June 28, 2016 03:51
-
-
Save namnv609/4e82f6e70afd7ab58d2c785c6e768b2f to your computer and use it in GitHub Desktop.
Example export CSV with CP932 in Ruby on Rails
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
require "csv" | |
class Admin::ExportsController < Admin::BaseAdminController | |
def index | |
admin = Admin.first | |
csv_string = CSV.generate do |csv| | |
csv << Admin.attribute_names | |
csv << admin.attributes.values | |
end | |
respond_to do |format| | |
format.csv {send_data csv_string.encode("CP932"), | |
:type => 'text/csv; charset=CP932'} | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment