Skip to content

Instantly share code, notes, and snippets.

@namnv609
Created June 28, 2016 03:51
Show Gist options
  • Save namnv609/4e82f6e70afd7ab58d2c785c6e768b2f to your computer and use it in GitHub Desktop.
Save namnv609/4e82f6e70afd7ab58d2c785c6e768b2f to your computer and use it in GitHub Desktop.
Example export CSV with CP932 in Ruby on Rails
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