Skip to content
This repository has been archived by the owner on Mar 5, 2024. It is now read-only.
/ who_dunit Public archive

Saves creator and updater of models in Rails apps using current user

License

Notifications You must be signed in to change notification settings

pbitty/who_dunit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NOTE: THIS IS ALPHA CODE

who_dunit

This module wires Rails to store the user that created and last-updated an ActiveRecord model.

Usage

In your model

    class Model < ActiveRecord:Base
        who_dunit # Enable saving of created_by and updated_by
    end

In your base controller class (usually ApplicationController)

	class ApplicationController < ActiveController:Base
		who_dunit # Enable tracking of current user
	end

Migrations

## TODO Write migration example

Design

In ApplicationController:

  • around_filter stores the current user in current thread for the duration of the action ** current user stored in thread-local variable

In Model:

  • has_one association to user for 'created_by'
  • has_one association to user for 'updated_by'
  • before_create calback sets 'created_by' column
  • before_save callback sets 'updated_by' column

In Migrations:

About

Saves creator and updater of models in Rails apps using current user

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages