2

I have a Microsoft Excel file (saved as a CSV file) that contains a list of names. A few of the names have letters with an accent over it, like so:

Maria Vásquez

In my seed file, I parse the CSV file to create Person instances, like so:

CSV.foreach("peopleFile.csv", headers:true, header_converters: :symbol, encoding:'iso-8859-1:utf-8') do |row|

  Person.create(
        name: "#{row[1]}"
    )

end

However, when I look in the Rails console, to see if that "á" came through fine with the accent over it, it appears like so:

name: "Maria V\u0087squez"

Also, when I render that person onto an HTML (html.erb) file, it appears like this on the webpage...completely ignoring the "a" altogether:

Maria Vsquez

Help. I thought I controlled for all of the character stuff when I included the " encoding:'iso-8859-1:utf-8' " bit in the "foreach" function that parses the CSV file. I would like any accented letters that is in my CSV file to appear that way in my database, in my console, and more importantly, on the web page. Thank you in advance :-)

Diana E.
  • 309
  • 5
  • 11
  • Are you sure the CSV file is ISO-8859-1? – mu is too short Nov 13 '16 at 21:03
  • Hey @muistooshort , how do I check to see if the file is ISO-8859-1? – Diana E. Nov 14 '16 at 08:47
  • Look at a hex dump and see if the `á` byte(s) match up with what ISO-8859-1 says they should be. – mu is too short Nov 14 '16 at 18:47
  • @muistooshort what is a hex dump? Can you please be more specific and explicit with where should I go to check these things out? I'm a junior developer. You didn't answer my question about how should I check to see fi the file is ISO-8859-1? – Diana E. Nov 15 '16 at 18:57
  • You see if the file is ISO-8859-1 by looking at a hex dump of the raw bytes in the file to see if they match up with the bytes from an [ISO-8859-1 character table](https://en.wikipedia.org/wiki/ISO/IEC_8859-1#Codepage_layout). Look for "hex editors" for whatever OS you're running. You could also go back to Excel and make it export the CSV as UTF-8 so that you don't have to worry about all this. – mu is too short Nov 15 '16 at 20:35

0 Answers0