Log the user who destroyed a record using 'before_destroy' callback

I want to log the user who destroyed a record using before_destroy callback. But, I dont know how to pass arguments to before_destroy(and I am not sure if it is possible). Maybe I am dealing this in the wrong way. Any other perspective to do this will also do.

I got it. I can add a virtual attribute to the model (something like attr_accessor :destroyer or something) and you can access it in the method for before_destroy callback. Something like:


@record = Record.find(params[:id])

@record.destroyer = current_user



attr_accessor :destroyer

before_destroy :log_destroyer

def log_destroyer

if destroyer

code for logging



Courtesy: Azolo who answered my question in SO. In case anyone is wondering how to do it :wink: