RubyGems Navigation menu

clerk 0.1.1

# Clerk Clerk adds the following attributes to your ActiveRecord objects * creator * updater Used in conjunction with the [`sentient_user`](https://github.com/bokmann/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 are using columns named `created_by_id` and `updated_by_id` on your database tables * these columns are foreign keys to users.id ## Installation 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 ## Setup Step 1: include the `sentient_user` SentientUser module on your User `/app/models/user.rb` class User < ActiveRecord::Base include SentientUser endis Step 2: include the `sentient_user` SentientController module on your ApplicationController `/app/controllers/application_controller.rb` class ApplicationController < ActionController::Base protect_from_forgery include SentientController # ... end 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 track_who_does_it end We probably want our User model to `track_who_does_it` as well class User < ActiveRecord::Base include SentientUser track_who_does_it end ## Usage 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 ## Resources used in the development of this gem * [http://ryanbigg.com/2011/01/extending-active-record/](http://ryanbigg.com/2011/01/extending-active-record/) * [http://charlotteruby.org/gem_workshop_tutorial/](http://charlotteruby.org/gem_workshop_tutorial/) * [http://yehudakatz.com/2009/11/12/better-ruby-idioms/](http://yehudakatz.com/2009/11/12/better-ruby-idioms/) * [http://www.cowboycoded.com/2011/01/31/developing-is_able-or-acts_as-plugins-for-rails/](http://www.cowboycoded.com/2011/01/31/developing-is_able-or-acts_as-plugins-for-rails/) * [http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html](http://api.rubyonrails.org/classes/ActiveRecord/Callbacks.html) * [https://github.com/bokmann/sentient_user](https://github.com/bokmann/sentient_user)

Gemfile:
= Copy to clipboard Copied!

install:
=

Versions:

  1. 1.0.0 - April 06, 2018 (9.5 KB)
  2. 0.3.0 - January 26, 2017 (9.5 KB)
  3. 0.2.3 - January 26, 2017 (9.5 KB)
  4. 0.2.2 - January 13, 2014 (8.5 KB)
  5. 0.2.1 - December 29, 2012 (7.5 KB)
  6. 0.1.1 - March 25, 2012 (8 KB)
Show all versions (7 total)

Runtime Dependencies (3):

railties ~> 3
sentient_user ~> 0.3.2

Development Dependencies (3):

bundler >= 1.1.3
rspec ~> 2.9.0
sqlite3 >= 0

Owners:

Authors:

  • Jesse House

SHA 256 checksum:

= Copy to clipboard Copied!

Total downloads 162,043

For this version 3,722

Licenses:

N/A

Required Ruby Version: None

Links: