Thufir
February 8, 2008, 12:41am
1
I’m trying to import csv data as per
http://www.jobwd.com/article/show/5
but can’t quite get the syntax:
thufir@arrakis ~/goodfellow-tool/db $
thufir@arrakis ~/goodfellow-tool/db $ rake
(in /home/thufir/goodfellow-tool/db)
rake aborted!
/home/thufir/goodfellow-tool/db/rakefile:12: syntax error, unexpected
tSYMBEG, expecting ‘)’
:name => name
^
/usr/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1940:in
`raw_load_rakefile’
(See full trace by running task with --trace)
thufir@arrakis ~/goodfellow-tool/db $
thufir@arrakis ~/goodfellow-tool/db $ cat rakefile
desc “load int data into development.sqlite3”
task :load_data => [“/home/thufir/goodfellow-tool/db/
data.csv”, :environment] do |t|
File.read(t.prerequisites.first).each do | line |
id,name=line.split(/,/)
Call.create(
:id => id
:name => name
)
end
end
thufir@arrakis ~/goodfellow-tool/db $
thufir@arrakis ~/goodfellow-tool/db $ sqlite3 development.sqlite3
SQLite version 3.4.1
Enter “.help” for instructions
sqlite> .schema
CREATE TABLE calls (“id” INTEGER PRIMARY KEY NOT NULL, “name” varchar
(255) DEFAULT NULL);
CREATE TABLE schema_info (version integer);
sqlite> SELECT * FROM calls;
1|zero
sqlite> .quit
thufir@arrakis ~/goodfellow-tool/db $
thufir@arrakis ~/goodfellow-tool/db $ cat data.csv
2,“two”
3,“three”
4,“four”
thufir@arrakis ~/goodfellow-tool/db $
thanks,
Thufir
Thufir
February 8, 2008, 1:08am
2
File.read(t.prerequisites.first).each do | line |
id,name=line.split(/,/)
Call.create(
:id => id
You need a comma after that last “id”.
:id => id,
Thufir
February 8, 2008, 1:14am
3
On Fri, 08 Feb 2008 00:07:17 +0000, Philip H. wrote:
You need a comma after that last “id”.
Thanks, that was an amazingly quick reply
It’s still failing:
thufir@arrakis ~/goodfellow-tool/db $
thufir@arrakis ~/goodfellow-tool/db $ rake
(in /home/thufir/goodfellow-tool/db)
rake aborted!
Don’t know how to build task ‘default’
(See full trace by running task with --trace)
thufir@arrakis ~/goodfellow-tool/db $
There’s no “default” task in the rakefile, though.
-Thufir
Thufir
February 8, 2008, 2:11am
4
On Fri, 08 Feb 2008 00:39:04 +0000, Philip H. wrote:
rake load_data
Or whatever your task name is…
Oh yeah, forgot. I was reading the directions, which include:
"But it’s important to include :environment in the task line - that
tells
Rails how to connect to the right database. "
http://www.jobwd.com/article/show/5
My rake command is failing with:
thufir@arrakis ~/goodfellow-tool/db $ rake load_data
(in /home/thufir/goodfellow-tool/db)
rake aborted!
Don’t know how to build task ‘environment’
(See full trace by running task with --trace)
thufir@arrakis ~/goodfellow-tool/db $
So I’m a bit stymied. I mean, presumably the rake file pulls data from
database.yml and so forth…
Thank you for all your help, I’m much closer to tangible results.
-Thufir
Thufir
February 8, 2008, 1:39am
5
Don’t know how to build task ‘default’
(See full trace by running task with --trace)
thufir@arrakis ~/goodfellow-tool/db $
There’s no “default” task in the rakefile, though.
rake load_data
Or whatever your task name is…