Active Record track changes with update_attributes

I am not sure I am thinking about this the correct way. I have a admin/maintenance scaffold to amend live data and I need to track the changes to data related to an order. e.g. change of address. I have a order_transaction model which I would like to record all of the data changes through the admin maintenance. I was hoping to use the AR tracking methods to help me. Rails 2.3.8

I do the normal read the order in from the database, pick up the attributes from params[:order} and then do an @order.update_attributes(params[:order]) The problem is that on success, @order.changes is nil. In the console:

ruby-1.8.7-p334 :024 > @o = Order.last   Order Load (0.4ms) SELECT * FROM "orders" ORDER BY orders.id DESC LIMIT 1

order.changes gives unsaved changes, so by design this will be empty after a successful save. You could do order.attributes = params[:order], inspect the changes and then save the object.

Fred

This might be useful. Worked well for me in the past. Works in Rails3 if you tweak the 'changes' bit as that is now reserved...

http://pjkh.com/articles/2009/02/02/creating-an-audit-log-in-rails

You could do order.attributes = params[:order], inspect the changes and then save the object.

Fred

@fred that worked perfectly.