Class: UserActionObserver

Inherits:
ActiveRecord::Observer
  • Object
show all
Defined in:
app/models/user_action_observer.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.current_userObject



16
17
18
# File 'app/models/user_action_observer.rb', line 16

def self.current_user
  Thread.current[:current_user]
end

.current_user=(user) ⇒ Object



8
9
10
# File 'app/models/user_action_observer.rb', line 8

def self.current_user=(user)
  Thread.current[:current_user] = user
end

Instance Method Details

#before_create(model) ⇒ Object



20
21
22
# File 'app/models/user_action_observer.rb', line 20

def before_create(model)
  # model.created_by = self.current_user
end

#before_update(model) ⇒ Object



24
25
26
# File 'app/models/user_action_observer.rb', line 24

def before_update(model)
  # model.updated_by = self.current_user
end

#current_userObject



12
13
14
# File 'app/models/user_action_observer.rb', line 12

def current_user
  self.class.current_user
end

#current_user=(user) ⇒ Object



4
5
6
# File 'app/models/user_action_observer.rb', line 4

def current_user=(user)
  self.class.current_user = user
end