title: Encoding issues for UTF8 CSV file when opening Excel and TextEdit
body: <p>I recently added a CSV-download button that takes data from database (Postgres) an array from server (Ruby on Rails), and turns it into a CSV file on the client side (Javascript, HTML5). I'm currently testing the CSV file and I am coming across some encoding issues. </p>
  
  <p>When I view the CSV file via 'less', the file appears fine. But when I open the file in Excel OR TextEdit, I start seeing weird characters like </p>
  
  <blockquote>
    <p>â€”, â€,  â€œ</p>
  </blockquote>
  
  <p>appear in the text. Basically, I see the characters that are described here: <a href="http://digwp.com/2011/07/clean-up-weird-characters-in-database/" rel="noreferrer">http://digwp.com/2011/07/clean-up-weird-characters-in-database/</a></p>
  
  <p>I read that this sort of issue can arise when the Database encoding setting is set to the wrong one. BUT, the database that I am using is set to use UTF8 encoding. And when I debug through the JS codes that create the CSV file, the text appear normal. (This could be a Chrome ability, and less capability) </p>
  
  <p>I'm feeling frustrated because the only thing I am learning from my online search is that there could be many reasons why encoding is not working, I'm not sure which part is at fault (so excuse me as I initially tag numerous things), and nothing I tried has shed new light on my problem.</p>
  
  <p>For reference, here's the JavaScript snippet that creates the CSV file! </p>
  
  <pre><code>$(document).ready(function() {
  var csvData = &lt;%= raw to_csv(@view_scope, clicks_post).as_json %&gt;;
  var csvContent = "data:text/csv;charset=utf-8,";
  csvData.forEach(function(infoArray, index){
    var dataString = infoArray.join(",");
    csvContent += dataString+ "\n";
  }); 
  var encodedUri = encodeURI(csvContent);
  var button = $('&lt;a&gt;');
  button.text('Download CSV');
  button.addClass("button right");
  button.attr('href', encodedUri);
  button.attr('target','_blank');
  button.attr('download','&lt;%=title%&gt;_25_posts.csv');
  $("#&lt;%=title%&gt;_download_action").append(button);
  });
  </code></pre>