Search code examples
ruby-on-railsrubyruby-on-rails-3acts-as-audited

Audited audited_changes confusion


Im using collectiveidea's audited solution for auditing in rails. So, there's a column (audited_changes) that is a TEXT definition in the database. When i retrieve an audit from the database, i get a plain string, and when i call that attribute in the view is non formated string. In the rdocs it says that theres a serialized hash of all changes. How can i get this hash? Also, in the same docs it says that there's access to old_attributes and new_attributes, how is this?

In my view:

<%= @audit.action %> # => update
<%= @audit.audited_changes %> # => --- name: - oldname - newname code: - oldcode - newcode

Or any chance on formatting this?


Solution

  • I think there might currently be a bug in audited. Are you using 3.0.0rc1? That is what I am using and I had something similar happen. First off, it didn't seem to recognize "Audit" as an ActiveRecord object, so I created an empty model in app/models/audit.rb. Once I did that I was seeing the behaviour you are seeing. To fix it, I removed the app/models/audit.rb and added an config/initializers/audited.rb with this in it:

    include Audited::Adapters::ActiveRecord