Maybe try this? http://stackoverflow.com/questions/5163339/write-and-read-a-file-with-utf-8-encoding Does it matter if every file is considered UTF-8 even if it never contains a UTF-8 character?
On Monday, July 14, 2014 5:01:11 AM UTC-6, Ruby-Forum.com User wrote: > > My Rails application (Rails 4.1, Ruby 2.1.1) offers the user to upload a > file. This file will then be parsed by the application, and after the > parsing is done, it is deleted from the upload area. > > So far, I have the following: > > In my upload form, I have > > <%= file_field_tag :upload, {accept: 'text/plain', class: > 'file_upload'} %> > > In my controller, params[:upload] contains an object of class Tempfile, > which is already opened for reading. I am using #readline to read > through this file. > > The problem now is that the file has encoding utf-8, and as soon as > reading contains a character which isn't also a 7-Bit ASCII character, I > get an exception. > > What is the best way to read an uploaded UTF-8 file? > > I was already thinking along the following line: The Tempfile class also > has a method #path, which returns the path of the uploaded file. I could > create a File object by opening this path, specify utf8 when opening it, > and read from this. > > However, since this problem must occur quite frequently, I wonder > whether there is a way (maybe in the file_field_tag) to tell Rails that > the Tempfile object should be opened as utf8 for reading. Is this > possible, or is there another good way to deal with this problem? > > -- > Posted via http://www.ruby-forum.com/. > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/c9aad9ce-0926-47c1-ac1f-64e8247594dc%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.