【发布时间】:2012-11-07 09:31:39
【问题描述】:
我已经建立了一个任务来导入这样的数据:
CSV.foreach(file, :headers => true) do |row|
question = Question.new ({
content: row[0],
mark: row[1],
topic_id: row[2],
question_type_id: row[3],
answers_attributes: [
{ content: row[5], correct: row[6] },
{ content: row[7], correct: row[8] }
]
})
question.user_id = row[4]
question.save!
这是我的 CSV 文件:
content, mark, topic_id, question_type_id, user_id, content, correct, content, correct
_____ are people involved in or affected by project activities, 5, 16, 1, 3, True, 't', False, 'f'
但是当我运行导入任务时,correct attribute 在数据库中总是为 FALSE,我尝试过使用不同的 PostgreSQL 的 Boolean Data Type 但无法正常工作。我怎么了?
【问题讨论】:
-
请向我们展示(生成的)SQL。我看起来像 't' 和 'f' 字段是多余的/多余的。
-
@DipakPanchal 它有错误:
Illegal quoting in line 2.@wildplasser 当我使用rake import时如何显示 SQL ? -
结果没有变化,两个答案行仍有正确列的值为
FALSE -
还是一样的结果,两个答案都是
FALSE(这是我为correct列设置的默认值),我已经尝试了Boolean Data type中的所有值。 -
如果您不使用 postgres 导入 csv:请删除 postgres 标签。 {content,correct} 字段在我看来仍然是重复的。
标签: ruby-on-rails ruby-on-rails-3 postgresql csv import