That's exactly it, (attribute)_change returns the pre-change value and the post-change value.
Keep an eye out for the word "transaction" also. I don't *think* you'll run into any problems with it using it as a model name, but if you start getting some really weird behavior when trying to persist models keep that in mind :) On Monday, February 2, 2015 at 3:45:12 PM UTC-8, James Miller wrote: > > I think it's the "_change" part. You're stomping on ActiveModel::Dirty ( > http://api.rubyonrails.org/classes/ActiveModel/Dirty.html) > > On Mon, Feb 2, 2015 at 3:42 PM, Scott Olmsted <[email protected] > <javascript:>> wrote: > >> A Rails 4.2 app has a table with about a dozen fields. Two have similar >> names: >> >> create_table :transactions do |t| >> ... >> t.decimal :shares, precision: 12, scale: 5 >> ... >> t.decimal :shares_change, precision: 12, scale: 5 >> ... >> end >> >> In tests the code assigns a scalar such as 12.4 or BigDecimal("12.4") to >> shares_change, but a puts statement shows that it has been set to an array >> (first element nil, second element a BigDecimal). Later puts statements >> just show it as nil. >> >> Here's a snippet: >> >> self.shares_change = -self.shares >> puts ">>>>> 2 /compute_shares_change/ self.shares=#{self.shares} >> self.shares_change=#{self.shares_change}" >> >> and the output: >> >> * >>>>> 2 /compute_shares_change/ self.shares=31.0 >> self.shares_change=[nil, #<BigDecimal:7f7fe3ba9158,'0.31E2',9(36)>]* >> But if I change the name of the first field to 'sharez' or move the >> declaration of the 'shares' field to right after the 'shares_change' field >> in the migration, the problem goes away: >> >> * >>>>> 2 /compute_shares_change/ self.shares=31.0 >> self.shares_change=-31.0* >> >> This happens with SQLite and with MySQL (version 5.1.58). It happens >> whether I use a factory (I'm using Fabrication in Minitest) to create the >> Transaction object or not. In all cases the declaration changes fix the >> problem. >> >> ActiveRecord bug? Just wondered if anyone else has encountered this. >> >> Thanks, >> >> Scott >> >> >> -- >> -- >> SD Ruby mailing list >> [email protected] <javascript:> >> http://groups.google.com/group/sdruby >> --- >> You received this message because you are subscribed to the Google Groups >> "SD Ruby" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected] <javascript:>. >> For more options, visit https://groups.google.com/d/optout. >> > > -- -- SD Ruby mailing list [email protected] http://groups.google.com/group/sdruby --- You received this message because you are subscribed to the Google Groups "SD Ruby" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
