I tried these both:
CSV.open(file.tempfile, "rb:CP850:UTF-8", {:headers => false, :col_sep
=> ";"})
CSV.open(file.tempfile, {:headers => false, :col_sep => ";", :encoding
=> "rb:CP850:UTF-8"})
it says 'No file to upload' !
I used the following code to show the encoding of my file:
utf8 = File.open("test.csv")
puts
utf8.external_encoding.name
it says CP850
I just opened my csv file with notepad and saved it with utf-8
encoding, then my original code is working perfectly and special
characters are shown normally.
Sebastian
On 22 Jun., 08:58, Chirag Singhal <
chirag.sing...@gmail.com> wrote:
> Per the documentation, you can probably do something like this:
>
> file = params[:file]
> CSV.open(file.tempfile, "rb:UTF-32BE:UTF-8", {:headers => false, :col_sep =>
> ";"}) do |row|
> @newhash << {:var1 => row[0], :var2 => row[1]}
> end
>
> Replace "UTF-32BE" with your incoming encoding and "UTF-8" with the encoding
> you want to parse/store your data in.
>
> On Wed, Jun 22, 2011 at 12:11 PM, Sebastian
> <
sebastian.go...@googlemail.com>wrote:
>
>
>
>
>
>
>
>
>
> > Hi Chirag,
>
> > thank you for the links. I will read them and look if there is
> > something that can help me.
>
> > I found out that the main problem was that my gvim editor saved every
> > *.rb file not in utf-8 encoding. I just edited them with notepad and
> > saved them explicitly in utf-8 and then the german special characters
> > worked in my controllers.
>
> > There is still the problem with the CSV class, which I need to import
> > a csv file. This class is not able to read the special characters.
>
> > I found the documentation here:
> >
http://www.ruby-doc.org/ruby-1.9/classes/CSV.html#M001340
>
> > there is something about encodings, but I don't understand how to use
> > it!!!
>
> > Sebastian
>
> > On 21 Jun., 14:34, Chirag Singhal <
chirag.sing...@gmail.com> wrote:
> > > Hi Sebastian,
>
> > > I personally haven't had to deal with encoding issues yet, but remember
> > > reading couple of posts from Yehuda Katz (of merb fame and core
> > contributor
> > > to rails) on that.
> > > Maybe these can help you identify and fix your problem:
> >
http://yehudakatz.com/2010/05/17/encodings-unabridged/http://yehudaka....
> > ..