hello everybody.
i need to log “who did what” on some models. i was reading recipe 59
of rails recipes and i created something like that:
class LogSweeper < ActionController::Caching::Sweeper
observe :model1, :model2, :model3, :model4, :model5, …
after_save(model)
save_log(model, “save”)
end
after_destroy(model)
save_log(model, "destroy)
end
private
save_log(model, event, user_id = controller.session[:account_id])
#create the log entry, i want to save the id of the model, the id
of the logged user and something to describe the action.
#controller isn’t defined here so i can’t access the user_id.
end
end
in environment.rb i added:
config.active_record.observers = :log_sweeper
the sweeper is called when something happen to the observed models,
but i can’t access the controller (and so, the user_id) from there.
any help?