How would i fix this code to update only if something has changed.
i am updating using csv, i need to change the confirmation field but only if something in the record has changed.
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
I think this will do