Fastercsv import fails with: ActiveRecord::StatementInvalid

This is more a ruby question than rails, really, but here goes:

How does the “row” ?variable? come into play? That is, how is it used?
Somehow, “login” needs to be defined so that the effect is similar to
what’s in db/migrate/001_calls.rb :

Call.create :login => “0123”

However, the data must be read from data.csv (which I can do), then,
somehow, Call.create needs to happen. No?

What I currently have:

[email protected] ~/goodfellow-tool/db $
[email protected] ~/goodfellow-tool/db $ ruby import.rb
/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/active_record/
connection_adapters/sqlite_adapter.rb:360:in table_structure': ActiveRecord::StatementInvalid (ActiveRecord::StatementInvalid) from /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/ active_support/core_ext/object/misc.rb:23:inreturning’
from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/
active_record/connection_adapters/sqlite_adapter.rb:359:in
table_structure' from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/ active_record/connection_adapters/sqlite_adapter.rb:210:incolumns’
from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/
active_record/base.rb:763:in columns' from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/ active_record/base.rb:2063:inattributes_from_column_definition_without_lock’
from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/
active_record/locking/optimistic.rb:45:in
attributes_from_column_definition' from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/ active_record/base.rb:1505:ininitialize_without_callbacks’
from /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/
active_record/callbacks.rb:225:in initialize' from import.rb:12:innew’
from import.rb:12
from /usr/lib/ruby/gems/1.8/gems/fastercsv-1.2.3/lib/
faster_csv.rb:1458:in each' from /usr/lib/ruby/gems/1.8/gems/fastercsv-1.2.3/lib/ faster_csv.rb:1003:inforeach’
from /usr/lib/ruby/gems/1.8/gems/fastercsv-1.2.3/lib/
faster_csv.rb:1175:in open' from /usr/lib/ruby/gems/1.8/gems/fastercsv-1.2.3/lib/ faster_csv.rb:1002:inforeach’
from import.rb:8
[email protected] ~/goodfellow-tool/db $
[email protected] ~/goodfellow-tool/db $ cat ruby import.rb
cat: ruby: No such file or directory
require ‘rubygems’
require ‘fastercsv’
require ‘/home/thufir/goodfellow-tool/config/environment.rb’

infile = “data.csv”

FCSV.foreach(infile) do |row|

    login = row[0]

    Call.new(
            :login => login
    )

end
[email protected] ~/goodfellow-tool/db $
[email protected] ~/goodfellow-tool/db $ cat data.csv
“one”
“two”
“three”
[email protected] ~/goodfellow-tool/db $

thanks,

Thufir

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs