acts_as_audited and “Declare either attr_protected or attr_accessible for User, but not both.”

By timothynjones

You’re using attr_accessible on your User model, to which you also want to audit changes using acts_as_audited.  Unfortunately it blows up with “Declare either attr_protected or attr_accessible for User, but not both.”  The problem is that acts_as_audited is adding its own attr_protected.  We can patch it in acts_as_audited.rb line 71 (as of this writing).  Change:

attr_protected :audit_ids

to

attr_protected :audit_ids if accessible_attributes.nil?

P.S. I would have commented directly on the acts_as_audited site in hopes of helping more people find this, but it appears that they’ve disabled comments.  Bummer.

2 Responses to “acts_as_audited and “Declare either attr_protected or attr_accessible for User, but not both.””

  1. Brandon Keepers Says:

    Timothy,

    Just so happens that I committed a fix for this yesterday (http://github.com/collectiveidea/acts_as_audited/commit/a799f388) and then came across your post, so I updated it to use accessible_attributes (http://github.com/collectiveidea/acts_as_audited/commit/b0c79ea4). Thanks!

  2. Felipe Giotto Says:

    Great!

    I was wondering what could be causing this weird error message! :D

Leave a Reply