Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Ruby Gem
“audited-activerecord”
By Hoang Van Quan
Contents
1. Introduction
2. Installation
3. Usage
1. Introduction
Audited (previously acts_as_audited) is an
ORM extension that logs all changes to your
models. Audited als...
2. Installation
gem "audited-activerecord", "~> 3.0"
$ rails generate audited:install
$ rake db:migrate
Upgrade
$ rails ge...
3. Usage
- Add “audited” into Model file.
class User < ActiveRecord::Base
audited
End
Specifying columns
class User < ActiveRecord::Base
# All fields
# audited
# Single field
# audited only: :name
# Multiple ...
Comments
user.update_attributes!(:name => "Ryan",
:audit_comment => "Changing name, just
because")
You can optionally add ...
Current User Tracking
s PostsController < ApplicationController
f create
urrent_user # => #<User name: "Steve">
@post = Po...
Associated Audits
class User < ActiveRecord::Base
belongs_to :company
audited :associated_with => :company
end
class Compa...
Accessible Attributes
class User < ActiveRecord::Base
audited :allow_mass_assignment => true
end
class User < ActiveRecord...
l
References
l https://github.com/collectiveidea/audited
l http://rdoc.info/github/collectiveidea/audited
l http://rdoc.in...
Thank you for listening!
Upcoming SlideShare
Loading in …5
×

Audited activerecord - QuanHV

1,744 views

Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Audited activerecord - QuanHV

  1. 1. Ruby Gem “audited-activerecord” By Hoang Van Quan
  2. 2. Contents 1. Introduction 2. Installation 3. Usage
  3. 3. 1. Introduction Audited (previously acts_as_audited) is an ORM extension that logs all changes to your models. Audited also allows you to record who made those changes, save comments and associate models related to the changes. Audited works with Rails 3. Supported Rubies: 1.8.7, 1.9.2, 1.9.3 ... Supported ORMs
  4. 4. 2. Installation gem "audited-activerecord", "~> 3.0" $ rails generate audited:install $ rake db:migrate Upgrade $ rails generate audited:upgrade $ rake db:migrate
  5. 5. 3. Usage - Add “audited” into Model file. class User < ActiveRecord::Base audited End
  6. 6. Specifying columns class User < ActiveRecord::Base # All fields # audited # Single field # audited only: :name # Multiple fields # audited only: [:name, :address] # All except certain fields # audited except: :password end
  7. 7. Comments user.update_attributes!(:name => "Ryan", :audit_comment => "Changing name, just because") You can optionally add the :comment_required option to your audited call to require comments for all audits. class User < ActiveRecord::Base audited :comment_required => true end
  8. 8. Current User Tracking s PostsController < ApplicationController f create urrent_user # => #<User name: "Steve"> @post = Post.create(params[:post]) @post.audits.last.user # => #<User name: "Steve"> d use a method other than current_user, put the following in an intializer: dited.current_user_method = :authenticated_user tside of a request, Audited can still record the user with the as_user metho dit.as_user(User.find(1)) do ost.update_attribute!(:title => "Hello, world!") d st.audits.last.user # => #<User id: 1>
  9. 9. Associated Audits class User < ActiveRecord::Base belongs_to :company audited :associated_with => :company end class Company < ActiveRecord::Base has_many :users has_associated_audits end
  10. 10. Accessible Attributes class User < ActiveRecord::Base audited :allow_mass_assignment => true end class User < ActiveRecord::Base audited :allow_mass_assignment => true end
  11. 11. l References l https://github.com/collectiveidea/audited l http://rdoc.info/github/collectiveidea/audited l http://rdoc.info/github/collectiveidea/audited
  12. 12. Thank you for listening!

×