You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
962 B

  1. # frozen_string_literal: true
  2. # == Schema Information
  3. #
  4. # Table name: admin_action_logs
  5. #
  6. # id :integer not null, primary key
  7. # account_id :integer
  8. # action :string default(""), not null
  9. # target_type :string
  10. # target_id :integer
  11. # recorded_changes :text default(""), not null
  12. # created_at :datetime not null
  13. # updated_at :datetime not null
  14. #
  15. class Admin::ActionLog < ApplicationRecord
  16. serialize :recorded_changes
  17. belongs_to :account, required: true
  18. belongs_to :target, required: true, polymorphic: true
  19. default_scope -> { order('id desc') }
  20. def action
  21. super.to_sym
  22. end
  23. before_validation :set_changes
  24. private
  25. def set_changes
  26. case action
  27. when :destroy, :create
  28. self.recorded_changes = target.attributes
  29. when :update, :promote, :demote
  30. self.recorded_changes = target.previous_changes
  31. end
  32. end
  33. end