Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>From <a href="http://www.ruby-doc.org/ruby-1.9/classes/CSV.html#M001343" rel="nofollow">CSV#read</a> docs:</p> <blockquote> <p>This method also understands an additional :encoding parameter that you can use to specify the Encoding of the data in the file to be read. You must provide this unless your data is in Encoding::default_external(). CSV will use this to deterime how to parse the data.</p> </blockquote> <p>So just to be safe, I would first use</p> <pre><code>COUNTRIES = CSV.read("/Users/dumitru/test.csv", { encoding: "UTF-8" }).flatten </code></pre> <p>and check what </p> <pre><code>COUNTRIES[2].encoding.name </code></pre> <p>says a) directly after <code>CSV#read</code> and b) when executed in your ERB template. If it says "US-ASCII" there then you should check whether something accidentally changes your COUNTRIES after parsing them. At least you can then be sure that something's odd inbetween.</p> <p>I would also prefer</p> <pre><code>&lt;%= "Country:" + COUNTRIES[id] %&gt; </code></pre> <p>since you already have strings there. But I don't think this will cure the issue, though. </p> <p>I couldn't imagine that something actually changed the contents of the string but maybe the encoding got reassociated as US-ASCII. So you might have a good chance to use</p> <pre><code>COUNTRIES[2].force_encoding("UTF-8") </code></pre> <p>with your string in order to enforce the association back to UTF-8. If that doesn't help I'd try</p> <pre><code>COUNTRIES[2].encode("UTF-8") </code></pre> <p>If all of these methods fail, I would need to know the encoding at the time you try to render the string in your ERB template to help you further.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload