2011-10-14 21:45:58 +01:00
|
|
|
class EventLog < ActiveRecord::Base
|
|
|
|
belongs_to :user
|
2014-01-21 04:51:49 +00:00
|
|
|
belongs_to :eventable, polymorphic: true
|
2011-10-14 21:45:58 +01:00
|
|
|
|
|
|
|
# self.per_page = 1
|
|
|
|
|
2014-03-11 07:39:25 +00:00
|
|
|
scope :eager_loading, -> { preload(:user) }
|
2014-03-11 11:47:03 +00:00
|
|
|
scope :default_order, -> { order(id: :desc) }
|
2011-10-14 21:45:58 +01:00
|
|
|
|
|
|
|
before_create do
|
2011-10-21 18:17:49 +01:00
|
|
|
self.user_name = user.try(:uname) || 'guest'
|
2012-04-26 02:38:33 +01:00
|
|
|
self.eventable_name ||= eventable.name if eventable.respond_to?(:name)
|
2011-10-14 21:45:58 +01:00
|
|
|
end
|
|
|
|
# after_create { self.class.current_controller = nil }
|
|
|
|
|
|
|
|
class << self
|
|
|
|
def create_with_current_controller(attributes)
|
|
|
|
create(attributes) do |el|
|
|
|
|
el.user = current_controller.current_user
|
|
|
|
el.ip = current_controller.request.remote_ip
|
|
|
|
el.controller = current_controller.class.to_s
|
|
|
|
el.action = current_controller.action_name
|
2012-03-29 20:19:00 +01:00
|
|
|
el.protocol = 'web'
|
2011-10-14 21:45:58 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def current_controller
|
|
|
|
Thread.current[:current_controller]
|
|
|
|
end
|
|
|
|
|
|
|
|
def current_controller=(ctrl)
|
|
|
|
Thread.current[:current_controller] = ctrl
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|