Rails プロジェクトの SQLite3 データベースの既存のテーブルに CSV ファイルをインポートしようとしています。
このソリューションで正しい答えを試しましたが、エラーが発生しました:
uninitialised constant Object::Points
メインディレクトリにある data.csv ファイルは次のとおりです。
Item,2003,2004,2005,2006,2007
AA2,43,34,23,52,24
TT2,48,39,29,23,29
app\models\points.rb に保存されているモデル ファイルは次のとおりです。
class Points < ActiveRecord::Base
attr_accessible :Item, :2003, :2004, :2005, :2006, :2007
end
db\migrate\20130709123346_create_points.rb に保存されている移行ファイルは次のとおりです。
class CreatePoints < ActiveRecord::Migration
def change
create_table :points do |t|
t.varchar(255) :Item
t.integer :"2003"
t.integer :"2004"
t.integer :"2005"
t.integer :"2006"
t.integer :"2007"
t.timestamps
end
end
end
以下は、上記のリンクにある正しい解決策に基づいて試したことです。
import.rake という名前の新しいファイルを作成し、lib\tasks\import.rake に保存しました。
require 'csv' csv_text = File.read('data.csv') csv = CSV.parse(csv_text, :headers => true) csv.each do |row| Points.create!(row.to_hash) end
次に
bundle exec rake import.rake
、コマンドラインで実行しました。
これを実行すると、次のエラーが表示されます。
uninitialised constant Object::Points
このエラーの原因となる何かが欠けているに違いありません。私は何を間違っていますか?