Reputation: 4663
The following code:
require 'csv'
desc "Import Voters from CSV File"
task :import => [:environment] do
file ="db/GOTV.csv"
CSV.foreach(file, :headers => true) do |row|
Voter.create({
:last_name => row[0],
:first_name => row[1],
:middle_name => row[2],
:name_suffix => row[3],
:primary_address => row[4],
:primary_city => row[5],
:primary_state => row[6],
:primary_zip => row[7],
:primary_zip4 => row[8],
:primary_unit => row[9],
:primary_unit_number => row[10],
:phone_number => row[11],
:phone_code => row[12],
:gender => row[13],
:party_code => row[14],
:voter_score => row[15],
:congressional_district => row[16],
:house_district => row[17],
:senate_district => row[18],
:county_name => row[19],
:voter_key => row[20],
:household_id => row[21],
:client_id => row[22],
:state_voter_id => row[23]
})
end
...is throwing the following error:
/Users/ecumbee/Desktop/cloudvoters/lib/tasks/import.rake:35: syntax error, unexpected $end, expecting kEND
end
^
I've tried removing the end, which throws the same error I've tried adding another end but it results in a can not compile error.
Edit: error when adding a second end statement
Don't know how to build task 'db:import'
Upvotes: 2
Views: 1125
Reputation: 139850
In the error message, $end
refers to the end of the input file, while kEND
refers to the end
keyword, so it's complaining about a missing end
, not an extra one.
If you still get a syntax error after adding another end
, that's something unrelated to this error.
Upvotes: 2
Reputation: 17735
The end
in your code is for the CSV.foreach ... do
block. You're missing another end
for the task ... to
block.
If that still gives you a syntax error, edit your question and post that error instead.
Upvotes: 2
Reputation: 6356
I know you said you tried to add another end and it didn't help, but the problem with your file is that it's missing the end
keyword that will end the task
task :import => [:environment] do
Then can you give more information about the error you're getting once you add the missing end
?
Upvotes: 1