title: Importing csv file on Ruby on Rails
body: <p>Sorry for my easy question because I'm so newbie in everything.</p>
  
  <p>As my question says, I wanted to import my csv file with header line into the existing data table. Even I tried for 4 days with these answers(and other googlings) 
  <a href="https://stackoverflow.com/questions/3682147/trouble-importing-csv-file-with-ruby-csv-module">Trouble importing csv file with ruby CSV Module</a>
  and
  <a href="https://stackoverflow.com/questions/4410794/ruby-on-rails-import-data-from-a-csv-file">Ruby on Rails - Import Data from a CSV file</a>
  , but I couldn't find the way.</p>
  
  <pre><code># db/migrate/20140923064239_create_restaurants.rb
  class CreateRestaurants &lt; ActiveRecord::Migration
    def change
      create_table :restaurants do |t|
        t.string :restaurant_category
        t.string :restaurant_subcategory
        t.timestamps
      end
    end
  end
  
  # lib/tasks/import.rake
  require 'csv'
  
  CSV.foreach("english.csv", :headers =&gt; true) do |row|
    Restaurant.create!(row.to_hash)
  end
  
  # english.csv
  restaurant_category,restaurant_subcategory
  kor,bakban
  kor,galbi
  kor,gobchang
  kor,hanjeong
  kor,hajang
  kor,dolsot
  kor,bude
  kor,jokbal
  kor,sullung
  chin,ssambab
  chin,dubu
  chin,jechum
  chin,pajeon
  </code></pre>
  
  <p>Then I did <code>rake db:migrate</code>, and got error message <code>NameError: uninitialized constant Restaurant</code>. I have tried many other ways in google but everytime this error message popped up. I just now assumes my existing Restaurant table is not working for this rake process(even though I don't know what this error message really means). </p>
  
  <p>So please help me for this problem and I'm very sorry for might-be-easy question. But too hard for me and I had no way to solve it. Thanks.</p>