title: How to change the encoding during CSV parsing in Rails
body: <p>I would like to know how can I change the encoding of my CSV file when I import it and parse it. I have this code:</p>
  
  <pre><code>csv = CSV.parse(output, :headers =&gt; true, :col_sep =&gt; ";")
  csv.each do |row|
    row = row.to_hash.with_indifferent_access
    insert_data_method(row)
  end
  </code></pre>
  
  <p>When I read my file, I get this error:</p>
  
  <pre><code>Encoding::CompatibilityError in FileImportingController#load_file
  incompatible character encodings: ASCII-8BIT and UTF-8
  </code></pre>
  
  <p>I read about <code>row.force_encoding('utf-8')</code> but it does not work:</p>
  
  <pre><code>NoMethodError in FileImportingController#load_file
  undefined method `force_encoding' for #&lt;ActiveSupport::HashWithIndifferentAccess:0x2905ad0&gt;
  </code></pre>
  
  <p>Thanks.</p>