title: How can I update specific row in db with csv file?(rails)
body: <p>I've used csv files for initial data to MySQL database. The method below was for that import process.(I asked it before in here stackoverflow, so it might be the case that I don't understand fully this process until now..)</p>
  
  <pre><code># lib/tasks/import.rake
  require 'csv'
  
  namespace :db do
    task :restaurants =&gt; :environment do
      CSV.foreach('public/seed_data/restaurants.csv') do |row|
        record = Restaurant.new(
          :name =&gt; row[0],
          :addr =&gt; row[1]
        )
        record.save!
      end
    end
  end
  </code></pre>
  
  <p>But now I have to just update some specific rows which has changed after my first db import. So I just changed my first method like below. My update.csv file has id, name(updated), addr(updated) columns with no head.</p>
  
  <pre><code># lib/tasks/import.rake
  require 'csv'
  
  namespace :db do
    task :restaurants_update =&gt; :environment do
      CSV.foreach('public/seed_data/update.csv') do |row|
        n = row[0]
        record = Restaurant.find(n)
        record.update_attributes(
          :name =&gt; row[1],
          :addr =&gt; row[2]
        )
        record.save!
      end
    end
  end
  </code></pre>
  
  <p>I thought it can read specific rows with row[0] which has restaurant_id to update, then update name and address with the followings(row[1] and row[2]). However when I do <code>rake db:restaurants_update</code>, it's saying <strong>ActiveRecord::RecordNotFound: Couldn't find Restaurant with id=1000001</strong>(it is my first row in csv file and my database has this record with id 1000001. I checked it out in console <code>Restaurant.find(1000001)</code>). I think import.rake might be missing my records.(can't read existing databases?)</p>
  
  <p>Can anyone point out my faults?</p>