def before_changes
old=self.class.find(id).attributes
@changes=[]
attributes.each do |key, val|
if val != old[key]
change = Change.new(:primary_key_id=>id,
:table=>self.class.table_name,
:attribute=>self.class.human_attribute_name(key),
:old=>old[key],
:new=>val) @changes << change
end
end
end
def after_changes
if(@changes.size>0) @changes.each {|change| change.save}
end
end
end
I now want to include it like this in my model class :
class Customer < ActiveRecord::Base
include Audit
…
end
But i get the error : “undefined method ‘before_update’ for
Audit::Module”
I can change it like this so it works fine:
class Customer < ActiveRecord::Base
include Audit
before_update :before_changes
after_update :after_changes
…
end
But this is not an ideal solution. I’d rather only include the one
include.
Any ideas???
The acts_as_versioned plugin is pretty close I imagine.
It looks like you’re using one table to audit all models. Acts as
Versioned uses a separate table for each model. The nice thing is
that each versioned record can also act like the actual method…