Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audit record has no user on first request posted to a server #26

Closed
dchelimsky opened this issue Sep 1, 2010 · 3 comments
Closed

Audit record has no user on first request posted to a server #26

dchelimsky opened this issue Sep 1, 2010 · 3 comments
Labels

Comments

@dchelimsky
Copy link

This happens in an app that uses acts_as_audited and relies on controller.current_user to provide the user to the Audit record. Steps to reproduce:

  1. start the server
  2. navigate to an edit form for an audited model
  3. re-start the server
  4. post the form

The audit record has no user.

This is happening because on line 28 of audit_sweeper.rb, the controller is nil.

The reason controller is nil is that the before hook on line 8 in action_controller/caching/sweeper.rb, which assigns the current controller to the @controller instance variable, is not called on the first request.

We were able to work around this issue in our app with the following addition to our ApplicationController.

require 'acts_as_audited/audit'
require 'acts_as_audited/audit_sweeper'
cache_sweeper :audit_sweeper, :only => [:create, :update, :destroy]

VERSIONS:

rails-2.3.5
acts_as_audited-1.1.1
ree-1.8.7-2010.01

@kennethkalmer
Copy link
Collaborator

Thanks for reporting David !

I've tested this on the new Rails 3 branch (discussed in #30) and cannot get the same behavour (luckily). Should we attempt to fix this on the old branch or are you fine with documenting it as a caveat in that branch's readme ?

@dchelimsky
Copy link
Author

Given the easy workaround, I'd say documenting it is fine.

@kennethkalmer
Copy link
Collaborator

Document caveat (closed by de6031f)

ktheory pushed a commit to ktheory/acts_as_audited that referenced this issue May 17, 2011
rocket-turtle pushed a commit to rocket-turtle/audited that referenced this issue Jan 4, 2023
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants