I have a Rails 3.2.14 app which has a Call
model with many different associations. I want to be able to track changes to the Call
model and somehow display a list of changes in the the Call
Show View.
I've been reading about the audited gem which looks like it might do the trick. But before I dive into this I'm wondering the following.
How can I call audits from within the show view? I assume I can do something like passing a block:
<% @call.audits.each do |a| %>
<%= a.action %> <%= a.audited_changes %>
<% end %>
Will something like this work in the show view when I need to see changes made for a specific call?
How does the audited
gem handle associations, especially has_many_through
?
I'm looking to implement this feature soon but don't want to introduce any problems into my app. I assume installing in a development environment might be the best route first?
If anyone has experience with this gem or can help provide answers, I'd really appreciate it.
Update
So I tried installing the audited gem and I was able to display the audit action and audited_changes. But the format of audited_changes is a serialized hash. How can I deserialize it and make the fields friendly? Also it appears that the gem does not record changes when using a has_many_through
relationship/join table. So what I have now is a half-working audit gem with data that's not user friendly. Any way to pretty this up and make it meaningful to the user?
call.rb excerpt
has_many :call_units
has_many :units, through: :call_units
belongs_to :nature
belongs_to :service_level
belongs_to :patient_sex
belongs_to :insurance
belongs_to :region
has_many :call_special_equipments
has_many :special_equipments, :through => :call_special_equipments
belongs_to :transferred_from, :foreign_key => :transfer_from_id, :class_name => 'Facility'
belongs_to :transferred_to, :foreign_key => :transfer_to_id, :class_name => 'Facility'
belongs_to :parent_call, class_name: "Call"
has_many :notes
belongs_to :cancel_reason