Class: RailsAdmin::History

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/rails_admin/extensions/history/history.rb

Constant Summary collapse

IGNORED_ATTRS =
Set[:id, :created_at, :created_on, :deleted_at, :updated_at, :updated_on, :deleted_on]

Class Method Summary collapse

Class Method Details

.create_history_item(message, object, abstract_model, user) ⇒ Object



18
19
20
21
22
23
# File 'lib/rails_admin/extensions/history/history.rb', line 18

def create_history_item(message, object, abstract_model, user)
  create(message: [message].flatten.join(', '),
         item: object.id,
         table: abstract_model.to_s,
         username: user.try(:email))
end

.history_for_model(abstract_model, query, sort, sort_reverse, all, page, per_page = (RailsAdmin::Config.default_items_per_page || 20)) ⇒ Object



25
26
27
28
# File 'lib/rails_admin/extensions/history/history.rb', line 25

def history_for_model(abstract_model, query, sort, sort_reverse, all, page, per_page = (RailsAdmin::Config.default_items_per_page || 20))
  history = where(table: abstract_model.to_s)
  history_for_model_or_object(history, abstract_model, query, sort, sort_reverse, all, page, per_page)
end

.history_for_object(abstract_model, object, query, sort, sort_reverse, all, page, per_page = (RailsAdmin::Config.default_items_per_page || 20)) ⇒ Object



30
31
32
33
# File 'lib/rails_admin/extensions/history/history.rb', line 30

def history_for_object(abstract_model, object, query, sort, sort_reverse, all, page, per_page = (RailsAdmin::Config.default_items_per_page || 20))
  history = where(table: abstract_model.to_s, item: object.id)
  history_for_model_or_object(history, abstract_model, query, sort, sort_reverse, all, page, per_page)
end

.latest(count = 100) ⇒ Object



14
15
16
# File 'lib/rails_admin/extensions/history/history.rb', line 14

def latest(count = 100)
  limit(count)
end