title: Uploading CSV File to Rails 4 DB via rake task
body: <p>I am trying to import data from a csv fle using a rake task (rake data:import) and am getting errors. I have been teaching myself rails the past few months but after a day and a half of googling I found many solutions to this, none of which i could get to work. </p>
  
  <p>Here is where I stand so far with my rake file:</p>
  
  <pre><code>require 'CSV'
  namespace :data do
    desc "Import teams from csv file"
    task :import =&gt; [:environment] do
      file=IO.read('filepath of my csv').force_encoding("ISO-8859-1").encode("utf-8", replace: nil)
  
      CSV.foreach(file, :headers =&gt; true) do |row|
        product.create ([
                         :name =&gt; row['name'],
                         :rating =&gt; row['rating'],
                         :year =&gt; row['year'],
                         :country =&gt; row['country'],
                         :state_or_province =&gt; row['state_or_province']]
                        )
      end
  
    end
  end
  </code></pre>
  
  <p>I am not getting any specific error (as far as I can tell). The output which confuses me is:</p>
  
  <pre><code>tasks/dataimport.rake:7:in `block (2 levels) in &lt;top (required)&gt;'
  </code></pre>
  
  <p>Is that output indicative of anything specific going on?</p>