Skip to content

Instantly share code, notes, and snippets.

@petrokoriakin
Created July 12, 2012 16:39
Show Gist options
  • Save petrokoriakin/3099215 to your computer and use it in GitHub Desktop.
Save petrokoriakin/3099215 to your computer and use it in GitHub Desktop.
Passing current_user into the model
#Aplication Controller
before_filter :define_current_user
def define_current_user
User.current_user = current_user
end
#User.rb (model)
class User
class << self
attr_accessor :current_user
end
end
#Account.rb (target model)
fires :updated,
on: :update,
actor: Proc.new { User.current_user },
data: :changes,
if: Proc.new { | acc | !acc.changes.blank? && acc.changes[:cancellation_code].blank? }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment