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

Rails3 support #30

Merged
2 commits merged into from
Feb 5, 2011
Merged

Rails3 support #30

2 commits merged into from
Feb 5, 2011

Conversation

ktheory
Copy link
Contributor

@ktheory ktheory commented Oct 5, 2010

Hey there,

Thanks for making acts_as_audited. It's a great plugin.

I got it working in my rails3 app with these two changes:

  • In AuditSweeper, use the modern API for observing.
    • Renamed the audits.changes column to audits.audited_changes to avoid ActiveRecord::DangerousAttributeError

Renaming the audits.changes column might be a hassle for legacy users, but it worked for me b/c I'm starting from scratch. If you know of a better way of circumventing the DangerousAttributeError, go for it!

Cheers,
Aaron

This fixes the Rails3 exception:
    ActiveRecord::DangerousAttributeError: changes is defined by
ActiveRecord
@dmitry
Copy link

dmitry commented Oct 21, 2010

Please update.

@ktheory
Copy link
Contributor Author

ktheory commented Oct 21, 2010

Hi Dmitry,

Please clarify what you'd like me to update.

I should point out that this patch only fixes acts_as_audited when it was installed on a Rails 2.x app.

That is, I created a rails 2.x app, installed acts_as_audited and generated the migration, then upgraded to rails 3 and applied this patch.

Creating a new rails 3 app and trying to run the acts_as_audited generator still breaks.

-Aaron

@dmitry
Copy link

dmitry commented Oct 21, 2010

Hi Aaron,

I think update of migration generator to a new rails isn't a real problem. What I really care is that the owner of this gem updated it with the rails 3 support. If it's only possible with a new migration generator (for rails 3), I can write patch and include it here.

Thank you.

@kennethkalmer
Copy link
Collaborator

Thanks Aaron

I think I'll branch of your work and clean the entire gem up so we can release a new major version that supports Rails 3 in all it's shining glory. This will take some work from my side, getting the test suite up to date and making the gem a Railtie...

Best

@kennethkalmer
Copy link
Collaborator

Hey guys

I've just pushed a huge bunch of changes to the 'rails3' branch for review. This would ultimately become acts_as_audited 2.0.0 once I get the thumbs up from everyone.

Please checkout the code locally, run 'bundle install', build the gem & install it and test it on a shiny new Rails 3 project.

Best

@x37v
Copy link

x37v commented Nov 18, 2010

So I've successfully installed the rails3 branch in my rails3 project and I'm auditing a few models but for all my audits there are no values in action or changes.

Audit.last.changes => {}
Audit.last.action => nil
Audit.last.auditable is filled..
Am I doing something wrong? This is in dev mode..

@ktheory
Copy link
Contributor Author

ktheory commented Nov 18, 2010

x37v:

Audit#changes was renamed to Audit#audited_changes.

ActiveRecord::Base now defines a "changes" method that returns a hash of changes attributes on that object. So we renamed "changes" to avoid collision.

@x37v
Copy link

x37v commented Nov 18, 2010

Ahh, I figured out my problem.
My project sends ActiveRecord::Base.send(:attr_accessible, nil) in an initializer, and since audited_changes and action are not defined as 'attr_accessible' they aren't set...

@dgm
Copy link
Contributor

dgm commented Nov 20, 2010

x37v: I ran into an error with checking for nil, checking empty? was better. Unless my app has something else funny, accessible_attributes should not be nil, but rather empty.

ruby-1.9.2-p0 > Email.accessible_attributes
 => #<ActiveModel::MassAssignmentSecurity::WhiteList: {}>
ruby-1.9.2-p0 > Email.accessible_attributes.nil?
 => false 
ruby-1.9.2-p0 > Email.accessible_attributes.empty?
 => true 
ruby-1.9.2-p0 > Email.accessible_attributes.count
 => 0 

See another issue I posted, as well as a pull request

@durrantm
Copy link

I was able to use the 2.x version but when I tried to install the 3.x version (2.0.0 rcl) on a brand new rails 3 project it failed with
$ bundle install
Fetching source index for http://rubygems.org/
Could not find gem 'acts_as_audited (= 2.0.0.rc1, runtime)' in any of the gem sources listed in your Gemfile.
my gem file has: gem "acts_as_audited", "2.0.0.rc1"
My Gemfile has source 'http://rubygems.org' as the first line.

@torgoton
Copy link

I have the same issue as durrantm. I don't see any "2.0.0.rc1" tag in the Switch Tags list either. Same for rc2.

@dgm
Copy link
Contributor

dgm commented Jan 2, 2011

I think I got around it by using rc2 instead of rc1 ... but in any case, I had to fork to fix a bug, and no one has responded to my pull requests yet.

@torgoton
Copy link

torgoton commented Jan 3, 2011

I used the acts_as_audited_rails3 gem for the time being.

@kennethkalmer
Copy link
Collaborator

Hi guys

Sorry for delays on posting here.

@dgm, your pull request is in along with others.

In general, use the following in your Gemfile until I get permissions to push to Rubygems

gem "acts_as_audited", "2.0.0.rc3", :git => "git://github.com/collectiveidea/acts_as_audited.git", :tag => "2.0.0.rc3"

Just keep track off the tags as I work towards a 2.0.0 stable.

@kilaru
Copy link

kilaru commented Feb 4, 2011

Thank you kenneth.

@zettworks
Copy link

Looks great. I managed to install acts_as_audited 2.0.0.rc3 on rails3 sample app. Changes to the model are recorded, but the audited_changes column stays empty. Do I have to change something more?

@kennethkalmer
Copy link
Collaborator

@zettworks, no, can you check against 2.0.0.rc4 (now on rubygems) and open a bug with some re-produceable steps that I can follow (if needed) ?

@bsiggelkow
Copy link
Contributor

Kenneth, you may already may know this, but I did some investigation, and changing the use of the deprecated 'reorder' method by Audit to use 'except(:order).order(...)' cannot happen until Rails 3 because of this bug https://rails.lighthouseapp.com/projects/8994/tickets/6011-exceptorderorder-is-not-working-in-scopes

@kennethkalmer
Copy link
Collaborator

Yep, very well aware of that. Watching that ticket until I find a cleaner solution (or it gets fixed).

It is more important for me to get the Railtie in, and release. I can always do a point release once we've figured out a way around it.

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet