Skip to content

Latest commit

 

History

History
49 lines (32 loc) · 1.18 KB

File metadata and controls

49 lines (32 loc) · 1.18 KB

The acts_as_blamable plugin stores the creator and updater of an ActiveRecord model.

gem install acts_as_blamable

Add a current_user class method to the User model, which returns for example the logged in user.

class User < ActiveRecord::Base
  def self.current_user
    ...
  end
end

class Post < ActiveRecord::Base
 acts_as_blamable
end

Add created_by and updated_by attributes to the posts table.

create_table :posts do |t|
  t.integer :created_by, :updated_by
end

Defaults

{ :current_user_method => 'current_user', :class_name => 'User', :creator_foreign_key => :created_by, :updater_foreign_key => :updated_by }

Modify the defaults if necessary

class Person < ActiveRecord::Base
  def self.current_person
    Person.first
  end
end

class Comment < ActiveRecord::Base
  acts_as_blamable :class_name => 'Person', :creator_foreign_key => :creator_id, :updater_foreign_key => :updater_id, :current_user_method => 'current_person'
end

Tested with Ruby on Rails version: 3.0.0 and ruby version Ruby Enterprise Edition 1.8.7 build 2010.02.