Created: 2012-03-25 18:53
Updated: 2019-01-21 18:13
License: mit


Build Status Code Climate

Clerk adds the following attributes to your ActiveRecord objects

  • creator
  • updater

Used in conjunction with the sentient_user gem, Clerk will automatically update these attributes using before_create and before_update ActiveRecord callback methods

The gem assumes the following:

  • you have a User model
  • you have a current_user method on your ApplicationController
  • you have 2 columns which are foreign keys of
    • the gems uses the following as defaults created_by_id and updated_by_id


Add this line to your application's Gemfile:

gem 'clerk'

And then execute:

$ bundle

Or install it yourself as:

$ gem install clerk

Then follow the directions under Setup

Version Notes

  • Use 0.2.x for rails 4
  • Use 0.3.x for rails 5


Step 1: include the sentient_user SentientUser module on your User /app/models/user.rb

class User < ActiveRecord::Base
  include SentientUser

Step 2: include the sentient_user SentientController module on your ApplicationController /app/controllers/application_controller.rb

class ApplicationController < ActionController::Base
  include SentientController

  # ...

Step 3: Add the track_who_does_it macro to any ActiveRecord models that have created_by_id and updated_by_id database columns

class Post < ActiveRecord::Base

We probably want our User model to track_who_does_it as well

class User < ActiveRecord::Base
  include SentientUser

You can optionally override the default column names created_by_id and updated_by_id

class Post < ActiveRecord::Base
  track_who_does_it :creator_foreign_key => "user_id", :updater_foreign_key => "updater_id"


Once you have finished the Setup and restarted your rails server your models should automatically update the creator and the updater attributes after being saved.

Since your models have the creator and updater attributes you can display these in any views

Updated by <%= @post.updater.full_name %> at <%= l(@post.updated_at, :format => :long) %>

Since we are using sentient_user you can also set the updater or creator in tests or rake tasks

user = User.find(5150)
user.make_current # now all models marked as track_who_does_it will save with this user tracked
Post.create!(:title => "New Post")
Post.last.creator == user # => true


In case you need to customize Clerk. Just create config/initializers/clerk.rb and set up your configuration:

Clerk.configure do |config|
  config.silence_warnings = true | false     # Defaults: false (true in test env)
  config.logger =       # Defaults: Rails.logger

Resources used in the development of this gem

Cookies help us deliver our services. By using our services, you agree to our use of cookies Learn more