title: How to import CSV to Rails app
body: <p>Rails 4.1.7
  Ruby 2.1.4</p>
  
  <p>I am trying to upload a CSV file to my app through a controller method:</p>
  
  <p>routes.rb</p>
  
  <pre><code>get 'csv_upload', to: 'users#csv_upload'
  </code></pre>
  
  <p>users_controller.rb
      def csv_upload</p>
  
  <pre><code> require 'csv'    
  
    customers = CSV.read('customers.csv')
  
    customers = CSV.parse(csv_text, :headers =&gt; true)
    customers.each do |row|
      Moulding.create!(row.to_hash)
    end
  
    redirect_to users_url
  
  end
  </code></pre>
  
  <p>CSV File customer.csv</p>
  
  <pre><code>gender ,age
  10,20
  11,20
  12,20
  13,20
  14,20
  15,20
  </code></pre>
  
  <p>It is located on the root directory. This is the error I get:</p>
  
  <pre><code>Errno::ENOENT in UsersController#csv_upload
  No such file or directory @ rb_sysopen - customers.csv
  
  Extracted source (around line #72):
  70
  71
  72
  73
  74
  75
  
  
  customers = CSV.read('customers.csv')
  customers = CSV.parse(customers, :headers =&gt; true)
  
  Rails.root: /Users/andreucasadella/rails_projects/hackcdmx
  </code></pre>