Hi Jim,

Looks that you have encoding problems, check your current encoding

puts Encoding.default_external

To solve your problem it should be UTF-8. Because according to the docs

*"File <http://www.ruby-doc.org/core-1.9.3/File.html> data written to disk
will be transcoded to the default external encoding when written."*
Or you can use additional options :encoding in CSV.generate

On Tuesday, November 13, 2012 9:24:01 AM UTC+2, jim wrote:

Hi guys!

I have a company model with a name attribute. Each company is association
a set of projects. I created a feature which allows users to
download a csv version of these projects. The download will give you a
zipped file of all projects grouped by company. So the zip file contains x
number of csv files where x is the number of companies. Everything is
working nice.

But when a user created a company whose name contains greek
characters, I suddenly get issues with encoding. Here's a small part of
the code that creates the zip file (i'm using zipruby btw)

Zip::Archive.open(file, Zip::CREATE) do |archive|
companies.each do |company|
data = CSV.generate(row_sep: "\r\n", quote_char: '"', force_quotes:
true) do |csv|
company.projects.each { |project| csv << project.name }

archive.add_buffer "#{company.name}.csv", data

so when company.name contains greek characters, i get a filename similar
to company??????.csv which cant be opened. I can't find a
way to set the encoding of the filename so I just gsubbed it and ignored
all non-ascii characters which is fine. But if one of the projects also
has a greek character, then the csv file will contain weird non-greek

Any help or insight is appreciated. Thanks!

visit my blog at http://jimlabs.heroku.com
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/74A_AKUpG08J.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

Discussion Posts


Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 2 of 3 | next ›
Discussion Overview
grouprubyonrails-talk @
postedNov 13, '12 at 7:22a
activeNov 14, '12 at 3:31p

2 users in discussion

Jim Ruther Nill: 2 posts Max Shytikov: 1 post



site design / logo © 2022 Grokbase