Re: acts_as_audited does not work with AS Nesting

71 views
Skip to first unread message
Message has been deleted

Blake B

unread,
Aug 27, 2007, 5:25:13 PM8/27/07
to actives...@googlegroups.com
I ran into this as well.  It's only a problem with caching enabled, and I found that if you comment out line # 602 in vendor/rails/actionpack/lib/action_controller/filters.rb then it works, but obviously this probably has ripple-effects for caching.

If you find out anything more, I'd love to hear it.

-Blake

On 8/23/07, CCH <c...@karensoft.com.my > wrote:

Hi

a) I installed the acts_as_audited plugin (which works in Prorduction
Mode only) and activated it with only 1 line of code at application.rb

audit User,Customer,Receivables

b) In my customer Controller I have

config.nested.add_link("Receivables", [:receivables])

c) Works perfectly (ie changes captured in the Audits table) until I
tried to access one of the nested tables (ie Receivables)  on AS and I
consistently got this error message


NoMethodError (undefined method `controller_name' for nil:NilClass):
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/caching.rb:602:in `callback'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/caching.rb:595:in `after'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/filters.rb:602:in `proxy_before_and_after_filter'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/filters.rb:470:in `call'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/filters.rb:470:in `call'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack- 1.13.3/lib/
action_controller/filters.rb:637:in `call_filter'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/filters.rb:638:in `call_filter'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack- 1.13.3/lib/
action_controller/filters.rb:438:in `call'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/filters.rb:637:in `call_filter'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack- 1.13.3/lib/
action_controller/filters.rb:638:in `call_filter'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/filters.rb:438:in `call'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack- 1.13.3/lib/
action_controller/filters.rb:637:in `call_filter'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/filters.rb:638:in `call_filter'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack- 1.13.3/lib/
action_controller/filters.rb:449:in `call'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/filters.rb:637:in `call_filter'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack- 1.13.3/lib/
action_controller/filters.rb:619:in `perform_action_without_benchmark'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/benchmarking.rb:66:in
`perform_action_without_rescue'
    C:/InstantRails/ruby/lib/ruby/1.8/benchmark.rb:293:in `measure'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/benchmarking.rb:66:in
`perform_action_without_rescue'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/rescue.rb:83:in `perform_action'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/base.rb:430:in `send'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/base.rb:430:in `process_without_filters'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/filters.rb:624:in
`process_without_session_management_support'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_controller/session_management.rb:114:in `process'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack- 1.13.3/lib/
action_controller/base.rb:330:in `process'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/
dispatcher.rb:41:in `dispatch'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel- 1.0.1-mswin32/
lib/mongrel/rails.rb:78:in `process'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/
lib/mongrel/rails.rb:76:in `synchronize'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel- 1.0.1-mswin32/
lib/mongrel/rails.rb:76:in `process'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/
lib/mongrel.rb:618:in `process_client'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel- 1.0.1-mswin32/
lib/mongrel.rb:617:in `each'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/
lib/mongrel.rb:617:in `process_client'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel- 1.0.1-mswin32/
lib/mongrel.rb:736:in `run'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/
lib/mongrel.rb:736:in `initialize'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel- 1.0.1-mswin32/
lib/mongrel.rb:736:in `new'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/
lib/mongrel.rb:736:in `run'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32 /
lib/mongrel.rb:720:in `initialize'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/
lib/mongrel.rb:720:in `new'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32 /
lib/mongrel.rb:720:in `run'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/
lib/mongrel/configurator.rb:271:in `run'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32 /
lib/mongrel/configurator.rb:270:in `each'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/
lib/mongrel/configurator.rb:270:in `run'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel- 1.0.1-mswin32/
bin/mongrel_rails:127:in `run'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/
lib/mongrel/command.rb:211:in `run'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel- 1.0.1-mswin32/
bin/mongrel_rails:243
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/
lib/active_support/dependencies.rb:488:in `load'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport- 1.4.2/
lib/active_support/dependencies.rb:488:in `load'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/
lib/active_support/dependencies.rb:342:in `new_constants_in'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport- 1.4.2/
lib/active_support/dependencies.rb:488:in `load'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/
commands/servers/mongrel.rb:60
    C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/
custom_require.rb:27:in `gem_original_require'
    C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/
custom_require.rb:27:in `require'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport- 1.4.2/
lib/active_support/dependencies.rb:495:in `require'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/
lib/active_support/dependencies.rb:342:in `new_constants_in'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport- 1.4.2/
lib/active_support/dependencies.rb:495:in `require'
    C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/
commands/server.rb:39
    C:/antRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:
27:in `gem_original_require'
    C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/
custom_require.rb:27:in `require'
    ./script/server:3
    -e:4:in `load'
    -e:4


Rendering C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/
actionpack-1.13.3/lib/action_controller/templates/rescues/layout.rhtml
(500 Internal Error)


Any ideas how to workaround this problem ?


CCH

unread,
Aug 28, 2007, 2:46:49 AM8/28/07
to ActiveScaffold : Ruby on Rails plugin
Hi Blake

On Aug 28, 5:25 am, "Blake B" <sha...@gmail.com> wrote:
> I ran into this as well. It's only a problem with caching enabled, and I
> found that if you comment out line # 602 in
> vendor/rails/actionpack/lib/action_controller/filters.rb then it works, but

cch: Err.. I don't have rails under my vendor directory
BTW,after dsabling cache,was acts_as_audited still capturing the audit
trail ?

> obviously this probably has ripple-effects for caching.
>
> If you find out anything more, I'd love to hear it.

cch:I will keep you postedon this group

>
> -Blake
>
> On 8/23/07, CCH <c...@karensoft.com.my> wrote:
>
>
>
>
>
> > Hi
>
> > a) I installed the acts_as_audited plugin (which works in Prorduction
> > Mode only) and activated it with only 1 line of code at application.rb
>
> > audit User,Customer,Receivables
>
> > b) In my customer Controller I have
>
> > config.nested.add_link("Receivables", [:receivables])
>
> > c) Works perfectly (ie changes captured in the Audits table) until I
> > tried to access one of the nested tables (ie Receivables) on AS and I
> > consistently got this error message
>
> > NoMethodError (undefined method `controller_name' for nil:NilClass):
> > C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
> > action_controller/caching.rb:602:in `callback'
> > C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
> > action_controller/caching.rb:595:in `after'
> > C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
> > action_controller/filters.rb:602:in `proxy_before_and_after_filter'
> > C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
> > action_controller/filters.rb:470:in `call'
> > C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
> > action_controller/filters.rb:470:in `call'

> > C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
> > action_controller/filters.rb:637:in `call_filter'

> > C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
> > action_controller/filters.rb:638:in `call_filter'

> > C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
> > action_controller/filters.rb:438:in `call'

> > C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
> > action_controller/filters.rb:637:in `call_filter'

> > C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
> > action_controller/filters.rb:638:in `call_filter'

> > C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
> > action_controller/filters.rb:438:in `call'

> > C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
> > action_controller/filters.rb:637:in `call_filter'

> > C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
> > action_controller/filters.rb:638:in `call_filter'
> > C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/

> > C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/mongrel-1.0.1-mswin32/
> > lib/mongrel.rb:736:in `run'

> > C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/
> > lib/active_support/dependencies.rb:342:in `new_constants_in'

> > C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/
> > lib/active_support/dependencies.rb:488:in `load'

> > C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/
> > commands/servers/mongrel.rb:60
> > C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/
> > custom_require.rb:27:in `gem_original_require'
> > C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/
> > custom_require.rb:27:in `require'
> > C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/
> > lib/active_support/dependencies.rb:495:in `require'
> > C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/
> > lib/active_support/dependencies.rb:342:in `new_constants_in'
> > C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.2/
> > lib/active_support/dependencies.rb:495:in `require'
> > C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/
> > commands/server.rb:39
> > C:/antRails/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:
> > 27:in `gem_original_require'
> > C:/InstantRails/ruby/lib/ruby/site_ruby/1.8/rubygems/
> > custom_require.rb:27:in `require'
> > ./script/server:3
> > -e:4:in `load'
> > -e:4
>
> > Rendering C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/
> > actionpack-1.13.3/lib/action_controller/templates/rescues/layout.rhtml
> > (500 Internal Error)
>

> > Any ideas how to workaround this problem ?- Hide quoted text -
>
> - Show quoted text -

Blake B

unread,
Aug 28, 2007, 1:40:43 PM8/28/07
to actives...@googlegroups.com
On 8/27/07, CCH <c...@karensoft.com.my> wrote:

Hi Blake

On Aug 28, 5:25 am, "Blake B" <sha...@gmail.com> wrote:
> I ran into this as well.  It's only a problem with caching enabled, and I
> found that if you comment out line # 602 in
> vendor/rails/actionpack/lib/action_controller/filters.rb then it works, but

cch: Err.. I don't have rails under my vendor directory
BTW,after dsabling cache,was acts_as_audited still capturing the audit
trail ?


Unfortunately no.  It requires the cache sweeper to be active to notice what has changed...

> obviously this probably has ripple-effects for caching.
>
> If you find out anything more, I'd love to hear it.

cch:I will keep you postedon this group

 Thanks, I'll do the same if I can figure anything else out.  I'm getting close to going to production with my app, so it may have to happen very soon!

-Blake

CCH

unread,
Sep 2, 2007, 10:35:37 AM9/2/07
to ActiveScaffold : Ruby on Rails plugin
Hi Blake/Lance

Have given up on acts_as_audited...

Just got an idea from Rails Recipes by Chad Fowler and have written my
own version which actually works and does not give any problem to
accessing of AS Nested Controllers. I am able to easily capture the
audit trail of goldberg user, record_id, record_type, event (CRUD),
created_at.

Using only one audit_trail table, I can even specify which model to
audit.
What I need to do now is to figure out how to serialize (the changes
to model's data ) into YAML by Active Record

Any insight into the serialization (into YAML) by Active Record is
appreciated.

Blake B

unread,
Sep 10, 2007, 3:38:20 PM9/10/07
to actives...@googlegroups.com
You should just be able to add this to the model:

serialize :attribute1, :attribute2

etc.
-Blake

CCH

unread,
Sep 11, 2007, 10:20:32 AM9/11/07
to ActiveScaffold : Ruby on Rails plugin
Hi Blake

Intriguing...

Can you give a more comprehensive example

My AuditSweeper.rb is as follows :-

class AuditSweeper < ActionController::Caching::Sweeper
# modules to be audited
observe
Customer,Contact,Engactua,Conactua,Workplan,Todolist,Vacation,Incident,Disbursement,Receivable,Payable,Far4staff,Productgroup,Mktpipeline,Wipbill,Projsma,Quotation

def after_destroy(record)
log(record, "DESTROY")
end

def after_update(record)
log(record, "UPDATE")
end

def after_create(record)
log(record, "CREATE")
end

def log(record, event, user = controller.session[:user],
username=current_user.login)
AuditTrail.create(:record_id => record.id, :record_type =>
record.type.name,
:event => event, :user_id
=>user, :name=>username)
end
end


Where and how should I add the serializing codes ?

> > > -Blake- Hide quoted text -

Blake B

unread,
Sep 12, 2007, 12:11:00 AM9/12/07
to actives...@googlegroups.com
I'm assuming you also have a normal model defined for AuditTrail?  Add a new column to the table (something like "revision_data"), and then add: serialize :revision_data to your audit_trail.rb file.  AuditTrail.create would need to include it in the hash obviously...

If you don't have an AuditTrail model and this is purely a cache sweeper, then (never tried this) you should be able to just store the result of "record.to_yaml " in another column... But you'd have to handle that serialize/deserialize yourself if you need to display it, etc.

-Blake

CCH

unread,
Sep 12, 2007, 8:28:16 PM9/12/07
to ActiveScaffold : Ruby on Rails plugin
Hi Lance/Blake/Ed Moss

I was wrong, using my own version of auditing also did not work with
nested controllers.
Using acts_as_audited, the moment it is activated, all modules with
nexted controllers wil get a 500 error when you try to access a nested
controller.
With my version, there was some improvement in that only controllers
with nested controlers marked for auditing will be affected.

The bottomline would be that nested controllers in AS simply don't
work if it is being observed.

Ed, I understand from the AS Homepage that nested controllers is your
area of expertise, can you point me in the right direction...

> > -Blake- Hide quoted text -

Ed Moss

unread,
Sep 14, 2007, 9:55:32 AM9/14/07
to ActiveScaffold : Ruby on Rails plugin
Did I hear my name?

So, acts_as_audited and nested controllers are not playing nice. To be
honest I have no experience with acts_as_audited but I did notice that
it uses polymorphic associations. There are several issues with
polymorphic associations in the issue list, unfortunately they are all
still open. One issue is slated to be fixed for the 1.1 release.

Ed.

CCH

unread,
Sep 14, 2007, 10:42:08 PM9/14/07
to ActiveScaffold : Ruby on Rails plugin
Hi Ed

On Sep 14, 9:55 pm, Ed Moss <edwin.m...@gmail.com> wrote:
> Did I hear my name?

cch: Yup !

>
> So, acts_as_audited and nested controllers are not playing nice. To be
> honest I have no experience with acts_as_audited but I did notice that
> it uses polymorphic associations. There are several issues with
> polymorphic associations in the issue list, unfortunately they are all
> still open. One issue is slated to be fixed for the 1.1 release.

cch

My alternative to acts_as_audited still had similar issues .
Perhaps, you can take a look at my simple auditsweer to see how it is
interfering with the nested controllers.

My AuditSweeper.rb is as follows :-

class AuditSweeper < ActionController::Caching::Sweeper
# modules to be audited
observe
Customer,Contact,Engactua,Conactua,Workplan,Todolist,Vacation,Incident,Disb­
ursement,Receivable,Payable,Far4staff,Productgroup,Mktpipeline,Wipbill,Proj­
sma,Quotation


def after_destroy(record)
log(record, "DESTROY")
end


def after_update(record)
log(record, "UPDATE")
end


def after_create(record)
log(record, "CREATE")
end


def log(record, event, user = controller.session[:user],
username=current_user.login)
AuditTrail.create(:record_id => record.id, :record_type =>
record.type.name,
:event => event, :user_id
=>user, :name=>username)
end
end


TIA

> > > - Show quoted text -- Hide quoted text -

CCH

unread,
Nov 6, 2007, 7:30:58 AM11/6/07
to ActiveScaffold : Ruby on Rails plugin
Hi

Issue now closed with a tip I got from Dubek on 6 Nov 2007.
It is as simple as

cache_sweeper :audit_sweeper, :only => [:update, :create, :destroy]

Brandon Keepers

unread,
Dec 13, 2007, 6:34:23 PM12/13/07
to ActiveScaffold : Ruby on Rails plugin
On Nov 6, 7:30 am, CCH <c...@karensoft.com.my> wrote:
> Hi
>
> Issue now closed with a tip I got from Dubek on 6 Nov 2007.
> It is as simple as
>
> cache_sweeper :audit_sweeper, :only => [:update, :create, :destroy]

I have committed an update to acts_as_audited that allows you to
specify this in your controller, instead of modifying the audit
sweeper:

class ApplicationController < ActionController::Base
audit MyModel, :only => [:create, :update, :destroy]
end

Let me know if you have any problems.

http://source.collectiveidea.com/public/rails/plugins/acts_as_audited

Thanks,
Brandon

CCH

unread,
Dec 19, 2007, 12:26:27 AM12/19/07
to ActiveScaffold : Ruby on Rails plugin
Hi Brandon

I am very pleasntly surprised to see you in this forum :-)

I'll checkout your new version andlet you know the results.

CCH
http://cch4...@blogspot.com
Reply all
Reply to author
Forward
0 new messages