Skip to content

Instantly share code, notes, and snippets.

@pashagray
Created November 22, 2016 11:28
Show Gist options
  • Save pashagray/699d3f4df33ee62e62e0a1162e46b685 to your computer and use it in GitHub Desktop.
Save pashagray/699d3f4df33ee62e62e0a1162e46b685 to your computer and use it in GitHub Desktop.
# base_controller.rb
before_filter :set_current_user
def set_current_user
User.current_user = current_user
end
# user.rb
def self.current_user=(user)
Thread.current[:current_user] = user
end
def self.current_user
Thread.current[:current_user]
end
# order.rb
event :complete do
transitions from: :processing, to: :completed,
after: Proc.new { self.completed_at = Time.now.utc },
on_transition: Proc.new { self.moved_to_completed_by = User.current_user }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment