0

我将如何修复此代码以仅在某些内容发生更改时才更新。我正在使用 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
4

1 回答 1

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
于 2012-10-13T04:08:58.160 回答