Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
##Custom VERSION table for User model
class UserVersion < PaperTrail::Version
self.table_name = :user_versions
attr_accessible :login, :first_name, :last_name, :email
end
# User Model
class User < ActiveRecord::Base
attr_accessible :id, :login, :password, :password_confirmation, :email, :first_name, :last_name
has_paper_trail :meta => { :first_name => :first_name,
:last_name => :last_name,
:login => :login,
:email => :email}, :class_name => 'UserVersion'
end
## VERSION table For user
class CreateUserVersions < ActiveRecord::Migration
def self.up
create_table :user_versions do |t|
t.string :item_type, :null => false
t.integer :item_id, :null => false
t.string :event, :null => false
t.string :whodunnit
t.string :first_name
t.string :last_name
t.string :login
t.string :email
t.text :object
t.datetime :created_at
end
add_index :user_versions, [:item_type, :item_id]
end
def self.down
remove_index :user_versions, [:item_type, :item_id]
drop_table :user_versions
end
end
#Initializer
module PaperTrail
class UserVersion < ActiveRecord::Base
attr_accessible :login, :first_name, :last_name, :email
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment