Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

ActiveRecord:"Dirty problems with decimal

#5394

I tried to implement a dirty filter in a model in rails3-rc2, ruby 1.9.2 to call a procedure if certain attributes were changed.

Even though I could not find documentation in edgeapi (other then ActiveModel::dirty) that was close to ActiveRecord:dirty rails2 documentation - I figured that the "changed?" method was there.

my after_save filter

def updateMax
  computeMax(self.assessment.id) if is_dirty?
end

def is_dirty?
  dirty =  (self.score_method_changed? or 
    self.weight_changed? or 
    self.critical_changed? or 
    self.minimum_value.changed?)
 end

The weight attribute is a decimal number (psql). If I update another field besides score_method(string), weight(decimal), critical(boolean), or minimum_value(integer) I get an error:

undefined method `changed?' for 2:Fixnum
Rails.root: /Users/salex/work/aidtdb3r3

Application Trace | Framework Trace | Full Trace
app/models/question.rb:37:in `is_dirty?'
app/models/question.rb:10:in `updateMax'
app/controllers/questions_controller.rb:65:in `block in update'
app/controllers/questions_controller.rb:64:in `update'

I also get the error if I update minimum_value without updating weight. But updating score_method or critical without updating weight works.

I got around it by getting the self.changed array and iterating thru the array to see if one of my fields was in the array.

Reported by Steve Alex · August 17th, 2010 @ 03:16 PM

State: stale
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Santiago Pastorino
    Santiago Pastorino
    • State changed from new to open

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    February 2nd, 2011 @ 05:00 PM

  2. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 2nd, 2011 @ 05:00 PM