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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
> `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 => idYou need a comma after that last "id". :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 > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Fri, 08 Feb 2008 00:07:17 +0000, Philip Hallstrom 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
>> 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.rake load_data Or whatever your task name is... --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Fri, 08 Feb 2008 00:39:04 +0000, Philip Hallstrom 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---