Can I use acts_as_audited in a rake task?

141 Views Asked by At

While acts_as_audited works fine with my models, I have a rake task which imports an XML file into my database. All the actions which are performed by this task (mainly create and update) are not picked up by the acts_as_audited. For the record I have added Audit.as_user(User.current_user) do; ... ; end in the rake task file and to the class which performs the actual task.

2

There are 2 best solutions below

1
On

acts_as_audited works with models which is an abstract of database table. It will log the altered table/model name, current column value and modified column value. Rake Tasks are not possible to log.

0
On

Finally I got it and it was no issue with acts_as_audited.

Apparently the Rake task which was updating the database was throwing errors. As soon as those corrected and the Task finished, I could see the audits on the tables.