V
V
Vayladion Gognazdiak2015-03-10 16:38:41
Ruby on Rails
Vayladion Gognazdiak, 2015-03-10 16:38:41

How to generate CSV with required encoding in RoR?

There is a controller in UTF-8
encoding. It is required to generate a CSV in cp1251 encoding. After generating and opening the file in Excel Windows, the encoding is confused and unreadable.
CHYADNT or where to dig?

# coding: utf-8

def generate_csv(csv_file_name)

data = CSV.generate do |csv|
  csv << [['Тест','Тест1'].join(';')]
  csv << [['1','2'].join(';')]
end

send_data data,
  type => 'text/csv; charset=windows-1251; header=present',
  disposition => "attachment; filename=#{csv_file_name}"

end

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
S
Shetani, 2015-03-10
@Shetani

Try to recode like this.
send_data data.encode("cp1251"),

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question