Topic: audited-activerecord [SOLVED]

i just installed the GEM audited-activerecord
This gem keeps track of data change on the DB and it works really good but i am having problem making a view for it.

on the console when i do

user = User.find(1)
user.audits.last

i get

SELECT "audits".* FROM "audits" WHERE "audits"."auditable_id" = 1 AND "audits"."auditable_type" = 'User' ORDER BY version DESC LIMIT 1
#<Audited::Adapters::ActiveRecord::Audit:0x007fd790c37278> {
                 :id => 11,
       :auditable_id => 1,
     :auditable_type => "User",
      :associated_id => nil,
    :associated_type => nil,
            :user_id => 1,
          :user_type => "User",
           :username => nil,
             :action => "update",
    :audited_changes => {
        "first_name" => [
            [0] "1moises xxxx",
            [1] "moises"
        ],
        "last_name" => [
            [0] "1zaragoza",
            [1] "zaragoza"
        ],
        "account_id" => [
            [0] 2,
            [1] 1
        ]
    },
            :version => 7,
            :comment => nil,
     :remote_address => "127.0.0.1",
         :created_at => Mon, 16 Jul 2012 13:56:07 UTC +00:00
}

and that is perfect

but i want to display this data.
so on my view
i do

= user.audits.count 

this tells me that i have 7 updates
but when i try to do

- user.audits do |audit|
  xxx

i dont get a single row back

Last edited by moiseszaragoza (2012-07-16 18:20:47)

Re: audited-activerecord [SOLVED]

update your view to look like

%table.table.responsive-table{:width => "100%"}
  %thead
    %tr
      %th{:scope => "row"}
      %th{:align => "left", :scope => "row"}= t(:field)
      %th{:align => "left", :scope => "row"}= t(:was)
      %th{:align => "left", :scope => "row"}= t(:is)
      %th{:align => "left", :scope => "row"}= t(:when)
      %th{:align => "left", :scope => "row"}= t(:by)
      %th{:align => "left", :scope => "row"}= t(:action)
      %th{:scope => "col"}
  %tbody
    - date = ''
    - user.audits.each do |x|
      - x.audited_changes.each do |xx|
        %tr-
          %td
            - if x.created_at != date
              -  date = x.created_at
              update Style
          %td
            -if xx[0] != nil
              = xx[0]
          %td
            -if xx[1] != nil
              = xx[1][0]
          %td
            -if xx[1] != nil
              = xx[1][1]
          %td
            = x.created_at
          %td
            -if x.user.try(:username?)
              = x.user.username
            - else
              = t(:system)
          %td
            = x.action

Re: audited-activerecord [SOLVED]

use
user.audits.each do |audit|
  xxx
end