如果某些内容发生了变化,我将如何修复此代码以进行更新。 我正在使用csv进行更新,我需要更改确认字段,但前提是记录中的某些内容已更改。
CSV.parse(atdecode,{headers: true, col_sep: "|", force_quotes: true, quote_char: "~", converters: :date}) do |row|
@contracts = Contract.unscoped.where(:unique3 => row[0]).first_or_create
@contracts.update_attributes( {
unique3: row[0],
prntkey23: row[1],
prntkey13: row[2],
act_code: row[3],
accounting_confirmation_date: row[4],
act_form: row[5],
act_net: row[6],
agent: row[7],
act_booked: row[8]
})
if @contracts.changed?
@contracts.update_attribute( {
confirmation: 0
})
end
end
答案 0 :(得分:1)
我认为这样做
@contracts.attributes = {unique3: row[0],
prntkey23: row[1],
prntkey13: row[2],
act_code: row[3],
accounting_confirmation_date: row[4],
act_form: row[5],
act_net: row[6],
agent: row[7],
act_booked: row[8]
}
@contracts.confirmation = 0 if @contracts.changed?
@contracts.save