[英]unexpected end syntax error
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'
The end
in your code is for the CSV.foreach ... do
block. 代码的
end
是CSV.foreach ... do
块。 You're missing another end
for the task ... to
block. 您错过了
task ... to
另一end
task ... to
阻止。
If that still gives you a syntax error, edit your question and post that error instead. 如果那仍然给您带来语法错误,请编辑您的问题,然后发布该错误。
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. 在错误消息中,
$end
指向输入文件的末尾,而kEND
指向end
关键字,因此它抱怨缺少end
,而不是多余的end
。
If you still get a syntax error after adding another end
, that's something unrelated to this error. 如果在添加另一
end
后仍然出现语法错误,则与该错误无关。
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 我知道您说过您尝试添加另一端,但没有帮助,但是文件的问题是它缺少将结束任务的
end
关键字
task :import => [:environment] do
Then can you give more information about the error you're getting once you add the missing end
? 然后,当您添加缺少的
end
您能否提供有关所得到的错误的更多信息?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.